필터 지우기
필터 지우기

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
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by