Using uimenu with multiple output nested function
이전 댓글 표시
I am attempting to use a the uimenu to access a nested fcn that has multiple variables I would like to be accessible from within the parent fcn. I tried using assignin to put the variable in the caller workspace, but I get the error "Error using assignin Attempt to add "coord" to a static workspace." Here is an example of what I am thinking:
uimenu(file,'Label','Open','Callback',@(varargin) openfile);
uimenu(tables,'Label','Nodes','Callback',@(varargin) fcnA(a));
function [a,b,c] = openfile
a=xlsread(obj,'a');
b=xlsread(obj,'b');
c=xlsread(obj,'c');
end
function fcnA(a)
%some function of 'a'
end
Perhaps if there is some other way to go about this, I am open to ideas. Thanks
채택된 답변
추가 답변 (2개)
Walter Roberson
2012년 12월 22일
Assign a value (any value!) to the variable before you define the nested functions. Once you have done that, the nested functions will be able to read and write the variable, without needing any "assignin".
For example,
function test_nested
a = []; b = []; c = [];
uimenu(file,'Label','Open','Callback',@(varargin) openfile);
uimenu(tables,'Label','Nodes','Callback',@(varargin) fcnA(a));
function openfile
a=xlsread(obj,'a');
b=xlsread(obj,'b');
c=xlsread(obj,'c');
end
function fcnA(a)
%some function of 'a'
end
end
Image Analyst
2012년 12월 22일
0 개 추천
openfile() does not have any input arguments, so obj inside of it is undefined. Also, I'm not sure 'a' is a valid range in Excel - you probably need to have both a starting cell designation and an ending cell designation, like 'A1:D42'.
Beyond that, I'm not really sure what you're trying to do. Are you trying to add a pulldown menu to an existing figure?
댓글 수: 5
Jeremy
2012년 12월 22일
Image Analyst
2012년 12월 22일
Why not just load up a listbox with all the .xls files. Would you consider using GUIDE, or do you like to roll your own?
Jeremy
2012년 12월 22일
Shaun VanWeelden
2012년 12월 22일
" I assume this will end up only loading files from the current directory though " - You can change the search path pretty easily to whatever root directory you want, user-defined or pre-defined. Hope that helps as you move forward. Let me know if you have questions
Image Analyst
2012년 12월 22일
Have you read the FAQ on this topic: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
카테고리
도움말 센터 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!