How to save some values from gui into a text file and load them elsewhere as a number?

1 view (last 30 days)
I have 2 values from an edit box and I want to write them in a txt file when I press a push button
function Masaedit_Callback(hObject, eventdata, handles)
% hObject handle to Masaedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
function Arias_Callback(hObject, eventdata, handles)
% hObject handle to Arias (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA
m=str2double(get(handles.Masaedit, 'string'));
assignin('base','m',m)
A=str2double(get(handles.Arias, 'string'));
assignin('base','A',A)
twovalues = fopen('twovalues.txt','w');
fprintf(twovalues,'%6d\t%3d',m,A);
fclose(twovalues);
But I want to save them as:
m=value;
A=value;
After the values are saved , I want to load the text file in a function like:
function xypr=twovalues (m,A)
CD=1;
load ('twovalues.txt',m,A)
ad=(-1/2)*((CD*A)/m);
end
But that it seems a little tricky and I don't know how should I do the conversion because for A,m = I need to load them as a string and for the result I should use something like str2double.
  2 Comments
Greg
Greg on 18 Mar 2018
First - why do you want to use a file? Are you just new to GUIDE and sharing data/variables between objects and callbacks?
Second - why a text file instead of a .mat file?
Third - what do you mean by:
But I want to save them as:
m=value;
A=value;
Stephen23
Stephen23 on 18 Mar 2018
Edited: Stephen23 on 18 Mar 2018
"But I want to save them as:"
m=value;
A=value;
"After the values are saved , I want to load the text file in a function like:..."
Why is this required? Is the aim just to move data from one callback/function to another? Why use a non-standard text format? If so, there are much simpler ways to do that: you might want to read this:

Sign in to comment.

Answers (0)

Categories

Find more on Entering Commands 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!