conditional selection on table

23 vues (au cours des 30 derniers jours)
abdul rehman
abdul rehman le 15 Juil 2020
Commenté : abdul rehman le 16 Juil 2020
I want the conditional selecton of a row in a table
  1. where name is ali
  2. where name is ali and age is between 25 to 30
  3. where name is ahmed, I want to multply his age with 2
kindly please help

Réponses (1)

KSSV
KSSV le 15 Juil 2020
Modifié(e) : KSSV le 15 Juil 2020
You can access the columns of the table using T.columnname or T.(1), T.(2) etc...
To get the index where name 'Ali' lies, you can use
idx = strcmp(T.name,'Ali') ; % assuming name column to carry names
idx = strcmp(T.(1),'Ali') ; % assuming first column to be names
To get the ages indices.
id = T(idx).age>= 25 & T(idx).age <= 30 ; % assuming age is the column whihc has ages
  1 commentaire
abdul rehman
abdul rehman le 16 Juil 2020
Thank, but its not doing the job. Its 2 line you suggested only returning the array of 0s and 1s. I need the whole row of the record where name ali is present. The last code you suggested is producing error
"Subscripting into a table using one subscript (as in t(i)) or three or more subscripts (as in t(i,j,k)) is not supported. Always specify a row subscript and a variable subscript, as in t(rows,vars)."
kindly if you can guide

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays 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