How to load a variable from workspace into the code of GUI?

4 次查看(过去 30 天)
I have developed a GUI.There I have placed an edit box and a push button.After writing a variable name from workspace with .mat extension in edit box, I click on push button whose first line in GUI code is N=get(handles.edit1,'string') hence "N" contains the name of that variable.The next line in the code is load N to load the variable for operations.But this generates error and command window says Unable to read file 'N': no such file or directory. Please suggest me a way to come out of this situation.

回答(1 个)

Image Analyst
Image Analyst 2013-6-30
N does not contain the name of any variable. N contains the string in your edit box called edit1. If, for some reason, you had your user type the file name of a mat file into that edit box instead of using uigetfile(), then you would do
storedStructure = load(N);
Now, the variable "storedStructure" (which is a structure) will contain all the variables that you saved into the mat file (when you called the save() function) as members ("fields") of that structure variable.
If the string in your edit box is the name of a variable instead of the name of a file, (it's hard to tell exactly from your description), then you'd have to know the name of the mat file somehow and use dynamic structure names to recall it. But this would be an unusual use of save() and load(), as almost always you know in advance what you want to save or recall from the mat file.
  2 个评论
Abbas
Abbas 2013-7-1
if you are saying N has edit1 in it then it is not correct.Because if i execute whos N then it appears in command window that N=variable_name.mat therefore it contains variable name.
Image Analyst
Image Analyst 2013-7-1
I didn't say that. I said that N contains whatever is IN edit1, not "edit1" itself. For example if you had abc in edit1, then N would be 'abc'. And typing whos N on the command line would show:
Name Size Bytes Class Attributes
N 1x3 6 char
It would not show 'abc.mat'. There is something you're not sharing with us.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by