Reading a variable from work-space into GUI
이전 댓글 표시
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
Walter Roberson
2012년 5월 27일
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
2012년 5월 27일
Walter Roberson
2012년 5월 27일
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
2012년 5월 27일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!