Performing equations on individual elements of a 3D Matrix, and then summing that along the z column
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
I have a 3D matrix of zeros called A, with a select 4x4 area in this set to 1. I then have a for loop where if A=0 an equation is performed and stores, and if A=1 a different equation is performed. Each value needs to be stored so they can be accessed later, and then I also need to produce the sum of each of the z collumns results. I have managed to build my 3D array, and can perform some functions on it, but not that which I am describing.
댓글 수: 0
답변 (3개)
You can write the whole computations w/o a for loop in a one-liner. For example, if the equation is A+2 if A == 0 and A.^2 if A == 1, you can write:
B = sum((A==0).*A+2 + (A==1).*A.^2, 3);
댓글 수: 0
Jos (10584)
2015년 7월 7일
What type of equation are you talking about?
This might get you started
Z = zeros(size(A)) ;
Z(A==0) = 2 % simple equation #1
Z(A==1) = 2*4 % simple equation #2
sum(Z,3) % sum over 3rd dimension, see help sum
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!