# Selecting only some rows of a matrix

4 visualizzazioni (ultimi 30 giorni)
MRC il 12 Dic 2013
Risposto: Andrei Bobrov il 12 Dic 2013
Hi, I have a matrix A mxn and I want to select only some of its rows satisfying this criterion: A(i,1)<=1e-03 && A(i,1)>=-1e-03 && A(i,2)<=1e-03 A(i,2)>=-1e-03 && A(i,3:end)<= 1e-03. I can't use loops.
Could you help me? Thanks
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Azzi Abdelmalek il 12 Dic 2013
idx=A(:,1)<=1e-03 & A(:,1)>=-1e-03 & A(:,2)<=1e-03 & A(:,2)>=-1e-03 & all(A(:,3:end)<= 1e-03,2)
B=A(idx,:)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (2)

Simon il 12 Dic 2013
Modificato: Simon il 12 Dic 2013
Hi!
So, what is "i"? Did you mean ":"? I assume ":" here.
Start by looking at the first criterion, you can write
crit1 = A(:, 1) <= 1e-3;
This will give you a logical vector. Do the same with the other criterions and combine them.
Hint: For the last criterion the function "all" is useful.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Andrei Bobrov il 12 Dic 2013
A(all(A(:,1:2) >= -1e-3,2) & all(A <= 1e-3,2),:)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Oceanography and Hydrology in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by