필터 지우기
필터 지우기

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 CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by