Check for incorrect argument data type or missing argument in call to function 'matlabFunction'.

Check for incorrect argument data type or missing argument in call to function
'matlabFunction'.
y = (p(1,i)-val(1)).^2+(p(2,i)-val(2)).^2;
a = 0;
b= 1;
g = matlabFunction(y)
t = fminbnd(g,a,b)

回答 (1 件)

Torsten
Torsten 2022 年 3 月 20 日
If i and p(1,i) and p(2,i) are defined, you should use
p(1,i) = 3.0;
p(2,i) = 15.0;
g = @(val)(p(1,i)-val(1)).^2+(p(2,i)-val(2)).^2;
t = fminbnd(g,a,b)

5 件のコメント

I defined i as
i = 1: 81
i is between 1 to 81
Torsten
Torsten 2022 年 3 月 20 日
The objective function for fminbnd must return a scalar. In your case, it returns a vector.
So either you sum all your squared differences or you call fminbnd in a loop, one i-value after the other.
Torsten
Torsten 2022 年 3 月 20 日
@Haruna Abba Usman comment moved here:
Please can you give me example with respect to my code. Like calling fminbnd in a loop as you said. Thank you
Torsten
Torsten 2022 年 3 月 20 日
編集済み: Torsten 2022 年 3 月 20 日
p(1,:) = 1:6;
p(2,:) = 3:8;
for i=1:size(p,2)
fun = @(x) (p(1,i)-x).^2 + (p(2,i)-x).^2;
sol(i) = fminbnd(fun,-6,6);
end
sol
Thank you

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

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2022 年 3 月 20 日

コメント済み:

2022 年 3 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by