Hi!
Have a short question :-)
I have the following code:
test = [1 2 3 4];
test = foo(test);
foo looks like this:
function [test, out] = foo(test)
out = 5;
test = foo(test) then return [1 2 3 4] not [1 2 3 4 5] which I thought it would do! What is it I do wrong here?!
One more thing:
If I write like this
function [test; out] = foo(test)
out = 5;
A ; instead of , Matlab gives me a syntax error, why?
Thanks!
Micke

 採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 7 月 4 日

0 投票

variant
function out = foo(test)
out = [test(:)',5];
end
2. You have:
function [test; out] = foo(test)
but we need to
function [test, out] = foo(test)

2 件のコメント

Mikael Brudfors
Mikael Brudfors 2011 年 7 月 4 日
Thank you!
Your variant works but why didn't you just write:
function out = foo(test)
out = [test,5];
end
Andrei Bobrov
Andrei Bobrov 2011 年 7 月 4 日
if [m, n] = size(test) and (m >1 , n >1) , then test(:)' - vector-row
eg:
test = [1 2;3 4] -> test(:)' = [1 3 2 4]

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by