Reading a variable from work-space into GUI
Show older comments
Hello. I am trying to make a gui which would allow a user to orgnize data useing eather a table or list. The problem is I don't know how to take allow gui to read from a workspace structure variable.
I have a structure varaible called xrddata, which has 4 sub structures: Name, X, Y, Z. ( and multiple number of these structures)
From what I understand I need to use evalin to get this values into the GUI handles. What I do not understand is how to use evalin to call in a xrddata and pull out the value of specific substructure such as name?
What I was thinking to do would be some thing like this
functuion update_listbox(handles)
for i=1:length(xrddata)
xrdvars(i)=evalin(xrddata(i).name)
end
set(handles.listbox1,'string',xrdvars)
First of how would I address xrddata with evalin command? Second is that the right approach?
Thanks
4 Comments
Walter Roberson
on 27 May 2012
Which workspace is xrddata in? Is it in the caller workspace, or is it in the base workspace? If it is not in either then evalin() would not be appropriate.
Consider just a single evalin() to bring the entire xrddata structure into the workspace of the GUI function, and pull it apart as needed.
To check: xrddata() is a structure array in which each array member has 4 fields? If so then "Name" is not a sub-structure of it, but there is a way to extract all of the Name fields into an array:
L = length(xrddata);
xrdvars = cell(1,L);
[xrdvars{1:L}] = evalin('base', 'xrddata.Name');
Alex
on 27 May 2012
Walter Roberson
on 27 May 2012
Once you have read xrddata in with the first evalin() you do not need to keep using evalin():
xrddata=evalin('base','xrddata')
L = length(xrddata)
xrdvars = cell(1,L) ;
[xrdvars{1:L}] = xrddata.name;
set(handles.listbox1,'string',xrdvars)
Another way of coding this is
xrddata=evalin('base','xrddata');
xrdvars = {xrddata.name};
set(handles.listbox1,'string',xrdvars)
The error you are getting about cell array of strings suggests that some of your xrddata(i).name are not strings and not numeric arrays, such as if they were cell arrays themselves. To check:
var_is_ok =cellfun(@ischar, xrdvars);
if all(var_is_ok)
disp('All entries look okay');
else
disp('Some entries are bad. See array elements #:');
disp(find(~var_is_ok));
end
Alex
on 27 May 2012
Answers (0)
Categories
Find more on Logical 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!