Pass GUI data to another .m file/function and from that to workspace
Show older comments
Hello. I am trying to make a GUI using GUIDE. For starters it will have a popupmenu and a pushbutton.
Things I have changed in the default-generated code:
In popupmenu1_CreateFcn to only show specific file extensions:
d = [dir('*.txt'); dir('*asc.dat')];
set(hObject, 'String', {d.name});
and in pushbutton1_Callback to get the filename:
handles.answer = get(handles.popupmenu1, 'Value');
I tried to write the filename into the figure's 'answer' path, I don't know if that is correct.
I then want to get that filename and enter it into another function in another .m file, that uses it like this:
function y = importfiledat(filename, startRow, endRow)
...
fileID = fopen(filename,'rt');
...
y = ...
The importfiledat function works fine when called by itself from the workspace and saves y as a variable there.
As it stands, running the GUI function shows correctly the popupmenu and pushbutton, but pressing the button results in various errors, an 'fopen error' between them. I tried calling the importfiledat function from the pushbutton1_Callback function or using assignin, evalin and whatever else I found, with no success.
Please advise as to how I can pass the information correctly.
Also, if I then add a plot in the GUI, will I have any problem getting an already drawn plot from the workspace? The position and characteristics of the GUI objects are changed from the .fig file? Shall I move the popupmenu dir text to that file somehow?
Is the more basic(?) functionality of normal programming way newbie-friendlier than GUIDE?
Thank you, D.
1 Comment
Jan
on 14 Dec 2017
It is not clear what "getting an already drawn plot from the workspace" means. What exactly is "a drawn plot"? Figures, axes and line objects created by plot are not part of "the" workspace. Any function has its own workspace, which is the set of locally used variables, but the diagrams are not variables.
Accepted Answer
More Answers (0)
Categories
Find more on Assembly in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!