How to pass values from guide to a function called by the script?
2 views (last 30 days)
Show older comments
How can I modify or input the values for min, sec , ora ,through guide, in functia proiectia called by the script proiectiasolve?
A part of the guide code : I have a series of editboxes where I put the values for some parameters. After I press a pushbutton it runs a script and assigns the values to workspace. function edit29_Callback(hObject, eventdata, handles)
y0(1,1)=str2double(get(handles.edit29,'String'));
%setappdata(handles.edit29,'x',y0(1,1));
assignin('base','x',y0(1,1))
function edit32_Callback(hObject, eventdata, handles)
second=str2double(get(hObject,'String'));
tspan=[0 : second];
assignin('base','tspan',tspan)
function minutsc_Callback(hObject, eventdata, handles)
% hObject handle to minutsc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%min=str2double(get(hObject,'String'));
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tspan = str2double(get(handles.edit32, 'string'));
assignin('base','tspan',tspan)
min=str2double(get(handles.minutsc, 'String'));
assignin('base','min',min)
x=str2double(get(handles.edit29, 'string'));
y=str2double(get(handles.edit26, 'string'));
z=str2double(get(handles.edit27, 'string'));
vx=str2double(get(handles.edit28, 'string'));
vy=str2double(get(handles.edit30, 'string'));
vz=str2double(get(handles.edit31, 'string'));
y0=[x;y;z;vx;vy;vz]
assignin('base','y0',y0)
an=str2double(get(handles.ancall, 'string'));
assignin('base','an',an)
luna=str2double(get(handles.lunasc, 'string'));
assignin('base','luna',luna)
zi=str2double(get(handles.zicall, 'string'));
assignin('base','zi',zi)
ora=str2double(get(handles.orasc, 'string'));
assignin('base','zi',zi)
sec=str2double(get(handles.seccall,'String'));
assignin('base','sec',sec)
m=str2double(get(handles.Masaedit, 'string'));
assignin('base','m',m)
A=str2double(get(handles.Arias, 'string'));
assignin('base','A',A)
proiectiasolve
When I press the pushbutton it runs proiectiasolve that contains:
h=1;
y = zeros(6, tspan(end)/h);
y(:,1) = y0;
for i=1:(tspan(end)/h)
H=sqrt(y(1,i)^2+y(2,i)^2+y(3,i)^2);
k_1 = proiectia(tspan(i), y(:,i), H, m, A, y(4:6, i));
k1=k_1;
k_2 = proiectia(tspan(i)+0.5*h, y(:,i)+0.5*h*k_1, H, m, A, y(4:6, i));
k2=k_2;
k_3 = proiectia((tspan(i)+0.5*h), (y(:,i)+0.5*h*k_2), H, m, A, y(4:6, i));
k3=k_3;
k_4 = proiectia((tspan(i)+h),(y(:,i)+k_3*h), H, m, A, y(4:6, i));
k4=k_4;
y(:,i+1) = (y(:,i) + (1/6)*(k1+2*k2+2*k3+k4)*h);
end
Rcsc = ((y(1,:).^2 + y(2,:).^2 + y(3,:).^2).^0.5);
plot(tspan,Rcsc)
Inside the loop there is a function named proiectia:
function yprim=proiectia(t,y,H,m,A,vit)
secundePeZi = 60*60*24;
n = datenum(an,luna,zi,ora,min,s);
n = n + t/ secundePeZi;
[an,luna,zi,ora,min,sec] = datevec(n);
miu=398600.4418*10^9;
magn=(y(1)^2+y(2)^2+y(3)^2)^(3/2);
yprim=zeros(6,1);
yprim(1,1)=y(4);
yprim(2,1)=y(5);
yprim(3,1)=y(6);
yprim(4,1)=double(-miu*y(1)/magn);
yprim(5,1)=double(-miu*y(2)/magn);
yprim(6,1)=double(-miu*y(3)/magn);
end
the min ,sec, ora and the others from n should be read from the workspace, but when I run the script I get the error:
Variable "min" has been previously used as a function or command name.
And it comes from here:
[an,luna,zi,ora,min,sec] = datevec(n);
0 Comments
Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps 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!