Help Print Command Error

9 views (last 30 days)
Kyle
Kyle on 7 Feb 2014
Commented: Mischa Kim on 7 Feb 2014
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 Comments
Mischa Kim
Mischa Kim on 7 Feb 2014
Do you simply want to display the variables in the command window? The print command is used to print a figure.
Kyle
Kyle on 7 Feb 2014
oh... yeah. thats what i'm trying to do.

Sign in to comment.

Answers (1)

Mischa Kim
Mischa Kim on 7 Feb 2014
Edited: Mischa Kim on 7 Feb 2014
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 Comment
Mischa Kim
Mischa Kim on 7 Feb 2014
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.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!