필터 지우기
필터 지우기

function retuning the whole vector

조회 수: 4 (최근 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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by