How to save some values from gui into a text file and load them elsewhere as a number?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Greg
2018년 3월 18일
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
2018년 3월 18일
편집: Stephen23
2018년 3월 18일
"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:
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!