operator .* is not supported for operands of type function_handle
50 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Ameer Hamza
on 1 Nov 2020
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 Comments
More Answers (1)
trung duc
on 31 Mar 2022
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))
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!