Effacer les filtres
Effacer les filtres

How to extract row intervals from a table to create a new one.

5 vues (au cours des 30 derniers jours)
Philippe Corner
Philippe Corner le 31 Jan 2018
Commenté : Peter Perkins le 7 Fév 2018
if I have a table
T:
v1 v2 v3 v4
a 1 1 5
b 3 3 7
c 2 5 7
d 5 5 2
e 5 7 7
How could i obtain all the columns from b and d rows as T2 table?
T2:
v1 v2 v3 v4
b 3 3 7
c 2 5 7
d 5 5 2

Réponses (2)

Walter Roberson
Walter Roberson le 31 Jan 2018
Modifié(e) : Walter Roberson le 31 Jan 2018
T2 = T1(2:4,:);
  4 commentaires
Philippe Corner
Philippe Corner le 1 Fév 2018
Thanks Mr. Walter, it is showing a mistake due to the == when I adapted it to my code.. do you have an idea why could it be?
Walter Roberson
Walter Roberson le 1 Fév 2018
Modifié(e) : Walter Roberson le 1 Fév 2018
The == could have difficulty depending on the data type involved. Perhaps you need
first_row = find(strcmp(T1.v1, 'b'), 1, 'first');
last_row = find( strcmp(T1.v1, 'd'), 1, 'first');

Connectez-vous pour commenter.


Peter Perkins
Peter Perkins le 1 Fév 2018
Walter interpreted "all the columns from b and d rows" as "FROM b TO d". I'm going to interpret it as "b AND d".
If the first variable in T has unique values, turn it into the row names, and just subscript:
T.Properties.RowNames = T.Var1;
T.Var1 = [];
t({'b' 'd'},:)
If they're not unique, use ismember to create a logical vector to use as a row subscript.
  2 commentaires
Walter Roberson
Walter Roberson le 1 Fév 2018
No, notice they wanted three lines of results, which can only be explained by wanting a range.
Peter Perkins
Peter Perkins le 7 Fév 2018
right you are.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by