Vector as an input in function

조회 수: 3 (최근 30일)
Valentina Richard
Valentina Richard 2022년 5월 29일
댓글: Valentina Richard 2022년 5월 31일
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?

채택된 답변

Matt J
Matt J 2022년 5월 29일
That should have worked.
func([1,2])
a = 1
b = 2
function func(v)
a=v(1), b=v(2),
end
  댓글 수: 1
Valentina Richard
Valentina Richard 2022년 5월 31일
Thank you so much for your help

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

the cyclist
the cyclist 2022년 5월 29일
편집: the cyclist 2022년 5월 29일
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
Anas Saleh
Anas Saleh 2022년 5월 30일
편집: Anas Saleh 2022년 5월 30일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by