Sum of index elements
4 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Azzi Abdelmalek
on 17 Nov 2014
Edited: Azzi Abdelmalek
on 17 Nov 2014
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 Comment
Azzi Abdelmalek
on 17 Nov 2014
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(:));
More Answers (1)
cob
on 17 Nov 2014
1 Comment
Azzi Abdelmalek
on 17 Nov 2014
Please delete this answer, and rewrite your comment by clicking on comment on this answer
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!