Get a 'for' loop to update itself by user input
    11 次查看(过去 30 天)
  
       显示 更早的评论
    
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
0 个评论
回答(1 个)
  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
...
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

