フィルターのクリア

operator .* is not supported for operands of type function_handle

50 ビュー (過去 30 日間)
Yi Chuan Xie
Yi Chuan Xie 2020 年 11 月 1 日
回答済み: trung duc 2022 年 3 月 31 日
Hi, I have a array, lets say[2 0 1 0]
I want each of them to be added by a number that is a proudct of the other two
a = 1
b = 2
so the answer should be [4 2 3 2]
However, when I write the code in Matlab like
array+a*b
it says operator .* is not supported for operands of type function_handle
what is wrong with my function?
THANKS

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 1 日
This code works without any error
array = [2 0 1 0];
a = 1;
b = 2;
y = array+a*b
It seems that in your case, one of the variable is defined as a function handle.
  8 件のコメント
Yi Chuan Xie
Yi Chuan Xie 2020 年 11 月 1 日
Thanks
Ameer Hamza
Ameer Hamza 2020 年 11 月 1 日
I am glad to be of help!

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

その他の回答 (1 件)

trung duc
trung duc 2022 年 3 月 31 日
clc;clear;
x = [0.1,0.1]';
k = 1;
alpha = 0.5;
A = [];
while k < 7000
f = @(x) cost(x);
A = @(x) [A;x' f];
gl = @(x) gradone(x);
x = @(x) x - alpha * gl;
k = @(x) k + 1;
end
A
min(A(:,3))
[a,b]= min(A(:,3))
plot(A(:,3))

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by