Help Print Command Error

2 次查看(过去 30 天)
Kyle
Kyle 2014-2-7
function [dy] = y(n,to,t,y0)
t=[0:0.01:5] h=[0.1 0.001] t0=0 y0=1 n=50 h=0.1 t=t0 y=y0
Hello, i'm new to matlab and have developed the following code for a euler solver. for i=1:n k=2-exp(-4*t)-2*y y=y+h*k t=t+h
print('t','y')
end
I'm trying to use the print command but am getting the following error.
Error using inputcheck (line 40) Multiple inputs that look like filenames: 't' and 'y'
Error in print (line 163) [pj, devices, options ] = inputcheck( pj, inputargs{:} );
Error in bmes511_hw3 (line 18) print('t','y')
Any ideas why?
  3 个评论
Mischa Kim
Mischa Kim 2014-2-7
Do you simply want to display the variables in the command window? The print command is used to print a figure.
Kyle
Kyle 2014-2-7
oh... yeah. thats what i'm trying to do.

请先登录,再进行评论。

回答(1 个)

Mischa Kim
Mischa Kim 2014-2-7
编辑:Mischa Kim 2014-2-7
OK. Use
sprintf('%5.2f: %5.2f', t, y)
or something like that. With the %5.2f you can specify the number format: total of five digits, two after the decimal point, fixed-point. Check out the documentation for a full description of the formatting syntax.
  1 个评论
Mischa Kim
Mischa Kim 2014-2-7
Careful, I just looked at your code. You first define t as a vector, then you re-assign it into a scalar by t = t0.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by