How to load a mat file (with its workspace) to GUI

Hi i am beginner in Matlab. i am trying to develop a GUI whereby i can extract some variables from a mat file. do some calculations in the GUI and then saved the output in the workspace again. i find difficulty in: 1. load a mat file with its workspace on gui 2. save the new variables after calculation back to the workspace again
thanks a lot.

2 Comments

i want to load the mat file with its own workspace to gui worksapce, perform calculation and save the variables back to the mat file.
The workspace of functions which you are using in GUI are different and Base workspace (which you see in matlab window) is different.
In which workspace you want to load the mat file -and- in which workspace you want to save variable ?
What do you mean by - "load a mat file (with its workspace)" ?

Sign in to comment.

 Accepted Answer

You can load the .mat file to your GUI function workspace using
load('YourFile.mat')
Once the vaiabled are loaded and calculation is completed, you can save a variable (say xyz) back to mat file using
save('YourFile.mat','xyz','-append')
For detailed info See
>> doc load
>> doc save

11 Comments

i already tried the load file as you are saying in the GUI m-file several times but it did not work out. it only orked out when i use load file in the command window and this is not the purpose of the GUI. is there something missing i.e., should i update any handles or is it because i am using an old version of Matlab (2007).
thanks alot
@yasmine: It is not a problem of your program or the Matlab version. You only expect the variable to appear in the wrong place. When you load the variables inside a function, they are visible exactly there: inside this function. See TAB's comment.
so the mat-file's workspace will not appear on the GUI workspace. the reason for asking this is that when i use the openvar function after that to open a variable in the mat-file that i loaded , i got a message that the variable does not exist.
Thanks
@yasmine:
There is nothing like "mat-file's workspace" in matlab.
---------
In matlab there are basically 2 types of workspace
-(1)-Base Workspace: Which you see at the side of command window. Variables which declared in command window or which are declared in m-script (not function) will be saved in basse workspace.
See http://www.mathworks.in/help/techdoc/matlab_prog/f7-38085.html
-(2)-Function workspace: Each function you write in matlab creates its own workspace. Variabled declared in functions are saved in its function workspace.
See http://www.mathworks.in/help/techdoc/matlab_prog/f0-38052.html
------
Now lets come on mat files. Mat files can be loaded independently in any worksace. If you call load('YourFile.mat') from command window or from script, variables will be loaded in base workspace. But if you call this from a function, variables will be loaded in that function's workspace.
i got your point. i try to use openvar funtion to open a variable that is in the function workspace but i got an error that the variable does not exist. should i update any handles. i don't know what is wrong?
thanks a million.
Once the function exited after completing execution, its workspace vanishes from memory. So function workspace variable will not open in editor window.
To make it work, prevent the function to exit after calling openvar(). To do this you can use some debugging tricks like put a breakpoint or use command "keyboard" after calling openvar() in your function.
thanks a lot Tab. i have tried the keyboard option and open the base workspace. thanks a lotttttttttt.
regards
is there another way of doing it without having to type return in the command window becasue i want to do it automatically in the GUI without having an input from the user at all.
You can use debugging commands like dbstop & dbquite to set & clear break points to stop the function from exiting.
See http://www.mathworks.in/help/techdoc/ref/dbstop.html
is this done after the keyboard command or do i use the dbstop/dbquit instead of it?
You don't need to set breakpoints at all. Just put that load() in your GUI program - the m-file - wherever you want it. It does not need to be loaded from the command line only.
S = load(fullFileName);
a = S.a;
otherVariable = S.otherVariable;
etc.
You could put this in it's own function, or in the OpenFcn, or wherever you want.

Sign in to comment.

More Answers (1)

Hi everyone ,
i am new in MATLAB , and i have done my project in it and now i need to create a GUI for my project.
using the GUI , i should be able to have the following things : in my project i have 2 different channels with their results. ( AWGN , BEC )
in each channel for example : AWGN , i have different SNR from 0.5 till 3.5.
in each value of the SNR , i have different code length values like : ( 8,16,32,64,128,256,512,1024,2048)
for each code length i have stored results .MAT file , in that file i need to extract a variable called indeces(order of numbers) , and then do some calculation ( show the first 10% , 20% , 30% ...100% of that variable indeces in a txt.file.
so the main idea is : select the channel type , select the SNR values , select the CODE LENGTH , choose the percentage , after that show the results in a .txt file so how to link all the above options together with the right results file. your help is appreciated and helpful...
Regards

2 Comments

Adam
Adam on 16 Feb 2017
Edited: Adam on 16 Feb 2017
Create a question for this, don't just tag it on as an answer onto a 5 year old question that has already been answered.
Dear Adam ,
Really sorry for disturbing you.
could you please help me in answering my questions, sure if you dont mind and have time for that. here is a link to my question : https://de.mathworks.com/matlabcentral/answers/325973-how-do-i-load-mat-files-into-gui-and-make-link-between-all-the-conditions-to-have-the-last-results

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Asked:

on 13 Mar 2012

Commented:

on 23 Feb 2017

Community Treasure Hunt

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

Start Hunting!