Vector as an input in function

3 visualizaciones (últimos 30 días)
Valentina Richard
Valentina Richard el 29 de Mayo de 2022
Comentada: Valentina Richard el 31 de Mayo de 2022
I am asked to create a function where one of the inputs is a vector containing parameters a and b (these are parameters of an equation f(x)).
I tried naming the vector v and then defining the vector before inputting the f(x) but it doesnt work. Can anyone help me on this please?

Respuesta aceptada

Matt J
Matt J el 29 de Mayo de 2022
That should have worked.
func([1,2])
a = 1
b = 2
function func(v)
a=v(1), b=v(2),
end

Más respuestas (1)

the cyclist
the cyclist el 29 de Mayo de 2022
Editada: the cyclist el 29 de Mayo de 2022
a = 2;
b = 3;
v = [a; b];
f_out = f(v)
f_out = 31
function out = f(v)
out = 5*v(1) + 7*v(2);
end
  1 comentario
Anas Saleh
Anas Saleh el 30 de Mayo de 2022
Editada: Anas Saleh el 30 de Mayo de 2022
please can you answer this question? I will appreciate that.
https://www.mathworks.com/matlabcentral/answers/1730385-image-processing-thresholding-images-to-obtain-image-with-the-required-gray-values

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by