필터 지우기
필터 지우기

I Want to perform element wise matrix multiplication

조회 수: 24 (최근 30일)
Nithya SIvasamy
Nithya SIvasamy 2017년 6월 12일
답변: Muhammed Musa 2020년 11월 26일
I have used the following code but getting an error message
I1=imread('abc.gif');
a=I1(1:3,1:3);
b=[-3 4 5;6 -7 1;-2 -4 -6];
c=a.*b;
The error message obtained is listed below Error using .* Integers can only be combined with integers of the same class, or scalar doubles.
How to clear this error
  댓글 수: 1
Stephen23
Stephen23 2017년 6월 12일
"I Want to perform element wise matrix multiplication"
This is a contradiction in terms: in MATLAB it is possible to perform element-wise multiplication OR matrix multiplication, but not both at the same time:

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2017년 6월 12일
I1=imread('abc.gif');
a=I1(1:3,1:3);
b=uint8([-3 4 5;6 -7 1;-2 -4 -6]);
c=a.*b;
You see you can multiply only same classes. Class of a is uint8, so you need to convert b into the same class.
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 6월 12일
You would probably be better off with
a = double( I1(1:3,1:3) );
b = [-3 4 5;6 -7 1;-2 -4 -6];
c = a.*b;

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Muhammed Musa
Muhammed Musa 2020년 11월 26일
A = [1 2 3 4];
B = [9 8 7 6];
A.*B =

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by