필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do I load a previously saved mat-flie into a GUI?

조회 수: 1 (최근 30일)
Mikkel Davidsen
Mikkel Davidsen 2013년 1월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
By using the GUIDE function in matlab, a GUI is run that prompts user for double input, and then saved as a .mat file. I want to load this file in another GUI.
Here is the relevant code from the first GUI:
function wallet_Callback(hObject, eventdata, handles)
valid = false; while valid == false myText = get(hObject, 'String'); temp = str2double(myText); if temp <10000.0 && temp > 1.0 playSound('002'); pause(0.5); save('walletSum.mat', 'myText'); valid = true; else disp('Input error.'); playSound('003'); pause(0.5); break end end guidata(hObject, handles);
This works, though clumsy it is. However, when I later want to load the m.file by:
function insert_bet_Callback(hObject, eventdata, handles)
bet = get(hObject, 'String'); % temp2 =load(walletSum___);
temp1 = str2double(bet); %temp2 = str2double(temp2);
if temp2>temp1 && temp1<0 %CheckSum<walletSum
playSound('003');
pause(0.5);
disp('Input error.');
else bet = temp1;
tempSum = temp2-temp1; %Withdraw money
walletSum = num2str(tempSum);
save('walletSum.txt', 'myText')
save('betSize', 'bet')
disp('WARNING: Bet subtracted from wallet.');
end guidata(handles.current_data);
I've put '%' because of the errors, until I would find a solution but I can't, and I can no longer ignore it. I get the "Undefined function or variable "walletSum"." - error. I'm obviously quite new to matlab, so forgive me for my ignorance.
If you could help me find a way so: The walletSum - bet is possible, and saved back into the same file, that would be great.
Thank you.

답변 (1개)

John Petersen
John Petersen 2013년 1월 24일
Instead of
temp2 = load(walletSum___);
try
load walletSum.mat
or try
wS = load(walletSum.mat);
temp2 = wS.myText;
If you can, next time give the exact error that is displayed.

이 질문은 마감되었습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by