Dear All, please if i have matrix of [1 2;4 3], i want to write a statement that can multiply every element by their fellow element and give final result in matrix. that is it will perform and give this kind of matrix: [1*1 1*2 1*4 1*3; 2*1 2*2 2*3 2*4] thanks

댓글 수: 1

Stephen23
Stephen23 2018년 11월 3일
See Bruno Luong's answer for the simple and efficient MATLAB solution.

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

 채택된 답변

madhan ravi
madhan ravi 2018년 11월 2일
편집: madhan ravi 2018년 11월 2일

1 개 추천

A=[1 2;4 3] %edited
[m,n]=size(A);
result=cell(1,m);
for i = 1:m
result{i}=[A(1,i).*(A)];
end
result=horzcat(result{:})

댓글 수: 2

mac-nic ifegbo
mac-nic ifegbo 2018년 11월 2일
편집: mac-nic ifegbo 2018년 11월 2일
Hi sir, yours is correct but what if is a bigger array. Am actually working with a 10 by 10 matrix. using your method will be very long
madhan ravi
madhan ravi 2018년 11월 2일
See edited answer now

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

추가 답변 (1개)

Bruno Luong
Bruno Luong 2018년 11월 2일

1 개 추천

Not clear what you want but KRON might be what you are looking for
>> A=[1 2; 4 3]
A =
1 2
4 3
>> kron(A,A)
ans =
1 2 2 4
4 3 8 6
4 8 3 6
16 12 12 9
>> kron(A,[1,2])
ans =
1 2 2 4
4 8 3 6
>> kron(A,[1;2])
ans =
1 2
2 4
4 3
8 6
>> kron([1,2],A)
ans =
1 2 2 4
4 3 8 6
>> kron([1;2],A)
ans =
1 2
4 3
2 4
8 6

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2018년 11월 2일

댓글:

2018년 11월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by