Borrar filtros
Borrar filtros

operator .* is not supported for operands of type function_handle

50 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 1 de Nov. de 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 comentarios

Iniciar sesión para comentar.

Más respuestas (1)

trung duc
trung duc el 31 de Mzo. de 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))

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by