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 comentarios

Walter Roberson
Walter Roberson el 27 de Mayo de 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
Alex el 27 de Mayo de 2012
So I made this code as per your suggestion and now I understand how to use the evalin! Thanks
xrddata=evalin('base','xrddata')
L = length(xrddata)
xrdvars = cell(1,L)
[xrdvars{1:L}] = evalin('base', 'xrddata.name')
set(handles.listbox1,'string',xrdvars)
I get this error though
"Cell array of strings may only contain string and numeric matrices"
Walter Roberson
Walter Roberson el 27 de Mayo de 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
Alex el 27 de Mayo de 2012
Thanks alot I was able to fix the issue with the erorr. and This showed me how to program the GUIDE code. I think I will be able to finsh the rest of my GUI now!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Preguntada:

el 27 de Mayo de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by