function retuning the whole vector

2 ビュー (過去 30 日間)
Omar Keele
Omar Keele 2021 年 2 月 21 日
コメント済み: Walter Roberson 2021 年 2 月 22 日
I have a function that input a matrix and a vector
function s= solve(A, b)
for i=1:N
s(i)= something
end
end
I want it to retunr the whole vector, like if disp(Solve(something)) would output a vector !
Can I use the return command here ?

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 21 日
That code outline already returns a whole vector. For example,
disp(mysolve(magic(6), [6;5;5;3;2;1]))
385 347 381 439 455 435
function s = mysolve(A,b)
for i = 1 : size(A,1)
s(i) = dot(A(i,:), b);
end
end
  4 件のコメント
Omar Keele
Omar Keele 2021 年 2 月 22 日
First line, N=size()
Is the order of filling the vector relevant?
Walter Roberson
Walter Roberson 2021 年 2 月 22 日
You take size(b, 2) which is the number of columns in b. But suppose you were passed a column vector then the number of columns would be 1.

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

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by