Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
Mikkel Davidsen
Mikkel Davidsen le 24 Jan 2013
Clôturé : MATLAB Answer Bot le 20 Août 2021
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.

Réponses (1)

John Petersen
John Petersen le 24 Jan 2013
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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by