Variable definition in a simple function
3 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Walter Roberson
on 17 Jul 2012
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.
More Answers (0)
See Also
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!