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

7 views (last 30 days)
Baris Gungordu on 16 Dec 2014
Edited: Julia on 17 Dec 2014
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

Julia on 16 Dec 2014
Edited: Julia on 16 Dec 2014
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
...
Julia on 17 Dec 2014
Edited: Julia on 17 Dec 2014
If your name for the first variable is a then in the OpeningFcn it should look like this:
handles.a=hObject;
handles.a = str2double(get(handles.edit14,'String'));
And don't forget to update the handles structure.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by