save continously
1 view (last 30 days)
Show older comments
Hello... i want to save value from "edit" GUI.. I have make it like this http://www.4shared.com/rar/jXNKKYPt/savecontinous.html, but it not suitable with my wish... I want to make value in "data1.mat" is different with "data2.mat" and so on, where the value i got from "edit" GUI when i pressed Save button... Thank you.. :)
function pushbutton1_Callback(hObject, eventdata, handles)
button_state = get(hObject,'Value');
if button_state == get(hObject,'Max')
for k=1:3
% save data to mat-file
x=str2num(get(handles.edit1, 'String'));
y=str2num(get(handles.edit2, 'String'));
z=horzcat(x,y);
myfilename = strcat('data', num2str(k), '.mat');
save (myfilename,'z');
% -------------
% this code to check value of data1.mat and so on
nil1 = isequal(strcat('data', num2str(k), '.mat'), strcat('data', num2str(k+1), '.mat'));
% in this chapter, i hope value of data2.mat and so on have save
% different value,, but it's not work.. How to save them with different
% value..??
if nil1 == 1
for k = 2:3
x=str2num(get(handles.edit1, 'String'));
y=str2num(get(handles.edit2, 'String'));
z=horzcat(x,y);
myfilename = strcat('data', num2str(k+1), '.mat');
save (myfilename,'z');
end
else
% when the button pressed, the "edittext" will be empty. So, user
% can input the value again
set(handles.edit1,'String','')
set(handles.edit2,'String','')
end
% ---------------------
end
else if button_state == get(hObject,'Min')
end
end
1 Comment
Answers (2)
Image Analyst
on 27 May 2012
Not exactly sure what you're trying to do, but nil1 will always be false since k is never equal to k+1. So your function will clear the edit fields (edit1 and edit2) on the first iteration, and in fact every iteration. The nil1 == 1 code will never get executed.
4 Comments
Image Analyst
on 27 May 2012
Not sure how x went from 5 to 7 and y went from 2 to 4, but see the code I posted and try to adapt it to whatever you want/need.
Image Analyst
on 27 May 2012
Try this (untested):
function pushbutton1_Callback(hObject, eventdata, handles)
folder = pwd; % or wherever you want.
try
% save data to mat-file
x=str2double(get(handles.edit1, 'String'));
y=str2double(get(handles.edit2, 'String'));
z = [x y];
for k = 1 : 3
% Save the file.
baseFileName = sprintf('data %d.mat', k);
fullFileName = fullfile(folder, baseFileName);
save (fullFileName,'z');
% Now we prepare for next time.
% Note: not really sure how x and y are
% supposed to be different each time through the loop.
x=str2num(get(handles.edit1, 'String'));
y=str2num(get(handles.edit2, 'String'));
z = [x y];
% Clear edit 2 for some reason.
set(handles.edit2,'String','')
end
% ---------------------
catch ME
errorMessage = sprintf('Error in function pushbutton1_Callback():\n%s', ME.message);
uiwait(warndlg(errorMessage));
end
0 Comments
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!