EULER'S METHOD GUI HELP

The y values of my euler method keeps on having a result of NaN's except for it's first value.
here is the code for the push button callback.
% --- Executes on button press in eul_solve.
function eul_solve_Callback(hObject, eventdata, handles)
% hObject handle to eul_solve (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
m = str2double(get(handles.iterations, 'string'));
t = zeros (m+1,0);
y = zeros (size(t));
h = str2double(get(handles.stepsize, 'string'));
t(1) = str2num(get(handles.tval, 'string')); %1st value of t
y(1) = str2num(get(handles.eul_ic, 'string')); %initial condition
for n = 1:m
t(n+1)=t(n)+h;
y(n+1)=y(n)+h.*(str2double(get(handles.eqn, 'string')));
end
result1 = t;
result2 = y;
result = ([t,y]);
set(handles.result1, 'string', result1);
set(handles.result2, 'string', result2);
could someone please point out where I've been wrong so that the y values will be displayed.

回答(1 个)

Rik
Rik 2019-4-9

1 个投票

You are using str2num (which you shouldn't), and you are setting a numeric vector as the string property. You may need to consider selecting only a single value, and you need to convert the number to a char (eg with sprintf).

3 个评论

Thank you for your answer.
How do I use this sprintf, and should I replace the str2num with sprintf?
Sorry for asking this much. I really don't know much about this program because I'm new to it.
You should read the documentation for the functions you are using. The Matlab documentation is very good, it is one of the advantages over their competitors.
If you open the doc for str2num you will see a banner telling you to use str2double instead.
Thank you! I'll consider reading more about it.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by