Given the row value of a specific variable in a table, find the corresponding row index.
54 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
yuxuan-z
el 30 de En. de 2020
Comentada: François LINANT
el 16 de Dic. de 2022
An extended question of this part:
Is there any way to locate the row indices of "Manchester City" and "Manchester United" (observations of the variable "Team" in the table) instead of 'observing the rows directly'?
Or more generally, given a value of a specific variable, how could I get its row index for extraction?
![question.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269132/image.png)
1 comentario
Geoff Hayes
el 30 de En. de 2020
Can you extract the first column (if that corresponds to team names) of data (from the table) and the do a find or strcmp (assuming cell array of strings for the teams) to get the row indices of those matching teams?
Respuesta aceptada
Vinai Datta Thatiparthi
el 3 de Feb. de 2020
Hello Yee,
Geoff's answer is spot on. If you were to put his idea into code, it would look something like this -
index = find(strcmp(table.Team, 'Manchester City') == 1);
To elaborate, table.Team isolates the first column of the table. The function strcmp compares the elements of the column cell vector with the string that you want to match (in this case, ManC). Further, the find function returns the index of the value which was a positive match from the string comparison.
Hope this helps!
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!