Making a matrix of same size from different matrices of same size

조회 수: 5 (최근 30일)
Hey all,
I have tried to find solution to my problem on MATLAB community, but I couldn't. So I am here to get the soultion to my problem.
I have a three matrices of same size. Now I need to make one matrix from three different matrices of same size.
For an example;
A = [ 0 13.2011 0 0 0;
13.2011 0 11.1861 0 0;
0 11.1861 0 0 0;
0 0 0 0 0;
0 0 0 0 0];
B = [ 0 0 0 0 0.0025;
0 .0256 0 0 0.0028;
.4563 0 0 0 0.0025;
0 0 0 0 0;
0.0025 0.0028 0.0025 0 0];
C = [0 0 0 0.145 0;
0 0 0 0 0;
0 0 0 18.254 0;
0 0 18.254 0 0;
0 0 0 0 0];
Now I need D matrix of same size. It is just a simple matrix, so elements of the indices will be changed from 0 to value or value to 0 depending on the condition, so I need general solution to make one Single matrix
Note; if the element of a matrix A is not a zero, then element of other two matrices will be zero always, even for 10*10 matrix.
For an example A(1,2) = some value, B(1,2) and C (1,2) will be zero.
I tried using below solution; But didn't work.
D (:,:,1) = - A;
D (:,:,2) = - B;
D (:,:,3) = - C;
After I got the matrix D, again I have to do some calculation on D and using D. So I need D matrix as D(n,m) not D(n,m,p);
It would be fine, if the matrix D(:,:,p) become D (:,:), but contains all the elements of A, B and C, not just oly C or B or A.
I hope my question is correct.
Any suggestions and answers are much appreciated.
Thanks in advance.
  댓글 수: 3
surendra kumar Aralapura mariyappa
Thanks Kalyan, sometimes, my brain will be dead. Anyways thank you so much,
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 20일
편집: KALYAN ACHARJYA 2019년 6월 20일
Haha..@Surendra Ji

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

채택된 답변

Aravind Ravikumar
Aravind Ravikumar 2019년 6월 20일
Hey, if only one element in same index of the matrix A,B,C will be non-zero, then you could just do D= A+B+C to get the following result. Is this how you want D to be combined as?
A =
0 13.2011 0 0 0
13.2011 0 11.1861 0 0
0 11.1861 0 0 0
0 0 0 0 0
0 0 0 0 0
B =
0 0 0 0 0.0025
0 0.0256 0 0 0.0028
0.4563 0 0 0 0.0025
0 0 0 0 0
0.0025 0.0028 0.0025 0 0
C =
0 0 0 0.1450 0
0 0 0 0 0
0 0 0 18.2540 0
0 0 18.2540 0 0
0 0 0 0 0
D =
0 13.2011 0 0.1450 0.0025
13.2011 0.0256 11.1861 0 0.0028
0.4563 11.1861 0 18.2540 0.0025
0 0 18.2540 0 0
0.0025 0.0028 0.0025 0 0

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by