Help Print Command Error

3 vues (au cours des 30 derniers jours)
Kyle
Kyle le 7 Fév 2014
Commenté : Mischa Kim le 7 Fév 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 commentaires
Mischa Kim
Mischa Kim le 7 Fév 2014
Do you simply want to display the variables in the command window? The print command is used to print a figure.
Kyle
Kyle le 7 Fév 2014
oh... yeah. thats what i'm trying to do.

Connectez-vous pour commenter.

Réponses (1)

Mischa Kim
Mischa Kim le 7 Fév 2014
Modifié(e) : Mischa Kim le 7 Fév 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 commentaire
Mischa Kim
Mischa Kim le 7 Fév 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by