필터 지우기
필터 지우기

Variable definition in a simple function

조회 수: 2 (최근 30일)
Haojie
Haojie 2012년 7월 17일
Hi all, I have a very simple function and cant get it work. I try to let t0(1)=t(2), t0(2)=t(3)... and write this function below. However it will show an error when I type t0=resize(t); in the command window. I have already defined t in another function.
Error in ==> resize at 2
k=2;
??? Output argument "t0" (and maybe others) not assigned during call to
"D:\HJ\Documents\MATLAB\resize.m>resize".
function t0=resize(t)
k=1;
while (k<size(t));
t0(k)=t(k+1);
k=k+1;
end
Your help is much appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2012년 7월 17일
size(t) is always going to return a vector, so your expression k<size(t) is going to be comparing k to a vector of values.
An evaluated expression is true when the result is nonempty and contains all nonzero elements (logical or real numeric). Otherwise, the expression is false.
Therefor the "if" will be false if there is any dimension within t for which 1 < size(t) is false. Which would occur if t is a vector (row vector or column vector) as the other dimension of a vector is 1, and 1 < 1 is false.
If you examine your code, if the very first iteration of the "while" does not occur, then you do not create t0 at all.
I suggest you read about length()
  댓글 수: 1
Haojie
Haojie 2012년 7월 17일
Thank you. I am a newbie on matlab, so I didnt check carefully of the size function. Seems I need to do more study on the manual first

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by