Hi, I have a matrix A(641x481) with numbers 0<x<3 and others matrix B,C,D and F with the same size of matrix A. I need create a matrix G, but depending the value of the element in A, the value in G will be the sum of different combinations of B,C, D and F. For example
If A(i,j) < 0.25; so G(i,j) = B(i,j) + C(i,j);
If 0.25< A(r,s)<1; so G(r,s) = B(r,s) + D(r,s);
etc
Thanks

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 17일
편집: Azzi Abdelmalek 2014년 11월 17일

0 개 추천

A=rand(4,5);
[n,m]=size(A)
B=rand(n,m)
C=rand(n,m)
D=rand(n,m)
G=zeros(n,m)
idx1=A < 0.25
G(idx1) = B(idx1) + C(idx1)
idx2=0.25<A & A<1;
G(idx2) = B(idx2) + D(idx2)

댓글 수: 1

A=rand(641,481);
[n,m]=size(A);
B=rand(n,m);
C=rand(n,m);
D=rand(n,m);
G=zeros(120686,1);
idx1=A < 0.25;
G(idx1(:)) = B(idx1(:)) + C(idx1(:));
idx2=0.25<A <1;
G(idx2(:)) = B(idx2(:)) + D(idx2(:));

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

추가 답변 (1개)

cob
cob 2014년 11월 17일

0 개 추천

Hi Azzi, I did exactly this but my matrix G instead of having 641x481 elements like the older ones, it has 120686X1 elements. I need to preserve the matrix shape to plot a distribution's plot after. Thanks

댓글 수: 1

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 17일
Please delete this answer, and rewrite your comment by clicking on comment on this answer

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

카테고리

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

질문:

cob
2014년 11월 17일

댓글:

2014년 11월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by