Error for assignment of Dynamic string for Struct array in GUI

1 次查看(过去 30 天)
Hi all,
I created a GUI programtically. I've a database (struct array) something like this
database.B01.Comp
database.K01.tur
database.C01.comp
.
.
.
etc.
I want to readin the data whenever the user selects particular type of data from a popupmenu. For instance, my callback function for the popup is.
function[] = pop11_2_Callback(varargin)
% get the string of the popmenu
S1 = (get(handles.pop1_2,'String'));
% Get the user selction of the string
S2 = (get(handles.pop1_2,'Value'));
% User selection
Sname = S1(S2);
%displaying the database corresponding to particular shaft.
database.(Sname).turbine
end
when I try to use this I get an error saying.
Argument to dynamic structure reference must evaluate to a valid field name.
Error in sample_gui/pop11_2_Callback (line 942)
database.(Sname).turbine(2,:)
Error while evaluating UIControl Callback
I tried to check it with the same code outside GUI and it works. But I'm not sure what is causing problem in my case.
Thanks in advance.

回答(1 个)

Walter Roberson
Walter Roberson 2016-2-2
Your code does not define Sname. Also, because you use str2num(), your S1 is a numeric vector so what you have named String will be a numeric value not a string.
  2 个评论
Bharath
Bharath 2016-2-3
I modified the code and I still get the error. I didn't use str2num. Please see my edited code again. Thanks in advance
Bharath
Bharath 2016-2-3
Thanks Mr. Walter. I found the error. It was with the Sname. Sname was cell array. So I chenged the code to char(Sname) and now it works.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by