Help Print Command Error

조회 수: 2 (최근 30일)
Kyle
Kyle 2014년 2월 7일
댓글: Mischa Kim 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