フィルターのクリア

Get a 'for' loop to update itself by user input

1 回表示 (過去 30 日間)
Baris Gungordu
Baris Gungordu 2014 年 12 月 16 日
編集済み: Julia 2014 年 12 月 17 日
I have a MATLAB GUI where I input the values for a,b,c,d,e,f. They are used to do calculations and produce a plot instantly. And I want to change them as a user several times. When I update values a,b,c,d,e,f, they get updated. However the 'CGPercent' calculation is not updated and uses the previous values. Problem is solved if I close the GUI and restart it for every new input set but not convenient for me.
Code:
a = str2double(get(handles.edit14,'String'));
b = str2double(get(handles.edit15,'String'));
c = str2double(get(handles.edit16,'String'));
d = str2double(get(handles.edit18,'String'));
e = str2double(get(handles.edit19,'String'));
f = str2double(get(handles.edit20,'String'));
for Veff=[a:b:c] %user input speeds (a,b,c) (comes from user)
q = 0.5*1.225*(Veff*1000/3600)^2;
F1=q*S; M1=q*S*Cref;
FX1=(F1*coef(:,1)); FZ1=(F1*coef(:,3)); MM1=(M1*coef(:,5));
W=[d*g:e*g:f*g]; %define mass range (d,e,f comes from user)
for lw=1:1:length(W)
XGEquation2max1 = ((((-FB*(Xa-Xb))-(((FX1(12)))*(Za-Zr))-(((FZ1(7))))*(Xa-Xr))-((max(MM1))))./W(lw)) + Xa;
CGPercent(lw,column) = (XGEquation2max1 - Cstart)/Cref * 100;
end
column=column+1;
end
speed_matrix = [a:b:c];
mass_matrix = [d:e:f];
ns = size(speed_matrix);
ns= ns(2);
count5 = 1;
for ns=1:1:ns
hold all
axes(handles.axes4)
plot(CGPercent(:,ns),transpose(mass_matrix)/1000)
count5 = count5 + 1;
end

回答 (1 件)

Julia
Julia 2014 年 12 月 16 日
編集済み: Julia 2014 年 12 月 16 日
Hi,
try this:
Initialize the variables at the beginning in the OpeningFcn:
handles.a=hObject;
handles.b= ...
% Update handles structure
guidata(hObject, handles);
Where you enter your new values:
handles.a=5 % the entered value
% Update handles structure
guidata(hObject, handles);
To call the variables you have to use
handles.a
handles.b
...
  2 件のコメント
Baris Gungordu
Baris Gungordu 2014 年 12 月 16 日
編集済み: Baris Gungordu 2014 年 12 月 16 日
Does the code should look like as below?
handles.edit14 = hObject; %for a
handles.edit15 = hObject; %for b
handles.edit16 = hObject; %for c..
Because when I do it like this, my editbox's does not become visible ( they are visible initially) and I get the error:
The name 'String' is not an accessible property for an instance of class 'figure'.
Julia
Julia 2014 年 12 月 17 日
編集済み: Julia 2014 年 12 月 17 日
If your name for the first variable is a then in the OpeningFcn it should look like this:
handles.a=hObject;
In your callback:
handles.a = str2double(get(handles.edit14,'String'));
And don't forget to update the handles structure.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by