Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

# Loop to separate rows in one matrix and delete elements in that matrix based on another matrix

1 Ansicht (letzte 30 Tage)
AS am 1 Okt. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
I want to write a for loop that will allow me to extract each row of a matrix and then remove elements from such rows based on elements in another matrix that meet a certain criteria. To explain this further, I have matrix b_loc, which is a 510x977 matrix and matrix z_probs which is a 510 x 977 x 2 matrix. For the first round of the loop I want to extract the first row of matrix b_loc then remove any values in that row that correspond to the positions z_probs(1,:,1)<0.5. For the second round of the loop I want to extract the second row of matrix b_loc then remove any values in that row that correspond to the positions z_probs(2,:,1)<0.5. And so on for all 510 rows. I have tried using the following code and I keep getting the error: Unable to perform assignment because brace indexing is not supported for variables of this type.
for i=1:510
b_aoi{i}=b_loc(i,:)
b_removed{i}=b_aoi{i}(z_probs(i,:,1)>0.5)
end
Any help would be greatly appreciated!

### Antworten (1)

Sindar am 1 Okt. 2020
% find indices where z_probs<0.5
idx = (z_probs(:,:,1)<0.5);
% "remove" those values in b_loc by setting them to NaN
b_loc(idx)=nan;
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
AS am 3 Okt. 2020
Thanks. This sort of worked. I had to add in additional steps for the for loop. But the idea helped.

### Community Treasure Hunt

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

Start Hunting!

Translated by