Effacer les filtres
Effacer les filtres

How to get a subtable out of a large table on conditions

6 vues (au cours des 30 derniers jours)
JFz
JFz le 9 Juil 2015
Commenté : JFz le 9 Juil 2015
I have a Matlab table A. I want to extract some rows from the table by certain key words and put the result into another table. The old table has 6 columns, I want to extract the first column to have value 'ATL', and the 3rd column to have value '7/7/2015'. How to do that?
tmpTbl = my_prices('ATL',:,'7/7/2015', :,:, :)
But it keeps saying error. I am totally confused here.
Thanks!

Réponse acceptée

Mohammad Abouali
Mohammad Abouali le 9 Juil 2015
mask=strcmpi(myTable.firstColumn(:),'ATL') & ...
strcmpi(myTable.thirdColumn(:),'7/7/2015');
newTable=myTable(mask,:);
of course change the 'firstColumn', 'thirdColumn', to their appropriate name (also goes for myTable and newTable).
  2 commentaires
JFz
JFz le 9 Juil 2015
Hi, Mohammad, Thank you so much! I tested the first part: mask=strcmpi(myTable.firstColumn(:),'ATL') It works. But when I include the 2nd part, it failed. I guess I didn't type it right. Besides, I don't understand the '&...'. Is there a link in mathworks that explain it? Thanks. Jen
JFz
JFz le 9 Juil 2015
This line: mask=strcmpi(myTable.firstColumn(:),'ATL') & ... strcmpi(myTable.thirdColumn(:),'7/7/2015');
| Error: Expression or statement is incomplete or incorrect.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by