Filter löschen
Filter löschen

operator .* is not supported for operands of type function_handle

50 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 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 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

trung duc
trung duc am 31 Mär. 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))

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by