function retuning the whole vector
Mostrar comentarios más antiguos
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 ?
Respuestas (1)
That code outline already returns a whole vector. For example,
disp(mysolve(magic(6), [6;5;5;3;2;1]))
function s = mysolve(A,b)
for i = 1 : size(A,1)
s(i) = dot(A(i,:), b);
end
end
4 comentarios
Omar Keele
el 22 de Feb. de 2021
Editada: Omar Keele
el 22 de Feb. de 2021
Walter Roberson
el 22 de Feb. de 2021
In the code structure you posted, your upper limit of your for loop is N, but N is not shown as having a value. In your actual code how are you defining the upper limit?
Omar Keele
el 22 de Feb. de 2021
Walter Roberson
el 22 de Feb. de 2021
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.
Categorías
Más información sobre Pulse width modulation (PWM) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!