Find element satisfying condition in 3D array, then apply operation to all elements in the column number
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Saeid
am 12 Mär. 2021
Kommentiert: Saeid
am 12 Mär. 2021
I have two 3D arrays A & B with I x J x K elements. I want to find all the elements that satisfy a certain condition in A (e.g. A<0). Now, if element A(i,j,k) satisfies this condition, I would like to apply some operation to ALL the elements that are in the coulmn j of array B.
How can I do this?
0 Kommentare
Akzeptierte Antwort
ANKUR KUMAR
am 12 Mär. 2021
Bearbeitet: ANKUR KUMAR
am 12 Mär. 2021
" I want to find all the elements that satisfy a certain condition in A (e.g. A<0). ": I hope you mean to find the indices of the elements which satisfies the given cretieria.
%creating a random matrix;
A=randi(5,5,3,4)-3
ind = find(A>0);
[ii,jj,kk] = ind2sub(size(A), ind);
[ii,jj,kk]
" I would like to apply some operation to ALL the elements that are in the coulmn j of array B. ":
for kk=1:size(A,3)
B(:,unique(jj),kk)= B(:,unique(jj),kk) *5 ; %some operation
end
Hope this helps.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!