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

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 17 Nov. 2014
Bearbeitet: Azzi Abdelmalek am 17 Nov. 2014

0 Stimmen

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 Kommentar

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(:));

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

cob
cob am 17 Nov. 2014

0 Stimmen

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 Kommentar

Azzi Abdelmalek
Azzi Abdelmalek am 17 Nov. 2014
Please delete this answer, and rewrite your comment by clicking on comment on this answer

Melden Sie sich an, um zu kommentieren.

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by