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

2 visualizaciones (últimos 30 días)
Baris Gungordu
Baris Gungordu el 16 de Dic. de 2014
Editada: Julia el 17 de Dic. de 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

Respuestas (1)

Julia
Julia el 16 de Dic. de 2014
Editada: Julia el 16 de Dic. de 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
...
  2 comentarios
Baris Gungordu
Baris Gungordu el 16 de Dic. de 2014
Editada: Baris Gungordu el 16 de Dic. de 2014
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 el 17 de Dic. de 2014
Editada: Julia el 17 de Dic. de 2014
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Scope Variables and Generate Names en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by