Using uimenu with multiple output nested function
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (2)
Walter Roberson
le 22 Déc 2012
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
1 commentaire
Jeremy
le 22 Déc 2012
Image Analyst
le 22 Déc 2012
0 votes
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 commentaires
Jeremy
le 22 Déc 2012
Image Analyst
le 22 Déc 2012
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
le 22 Déc 2012
Shaun VanWeelden
le 22 Déc 2012
" 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
le 22 Déc 2012
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
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!