- See strfind, contains and friends,
- intersect
How to search a table for a string
597 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have a table of data. One of these columns includes a column which I have labelled 'Participant Data'
I want to search 'Participant Data' for a particular string and return all the index of this table when it does pop up.
Additionally if I have 2 arrays of indices, how to return just the numbers that are in both indices?
Thanks!
1 comentario
Respuestas (1)
Abhisek Pradhan
el 16 de Mzo. de 2020
4 comentarios
Samad
el 10 de En. de 2023
strcmp does not work with table, it works with cell. First we have to convert table into cell.
Run the following code
name=["sam"; "jack"];
age=[20'; 27]; height=[4; 5];
tab=table(name, age, height)
extract the name sam
idx=strcmp("sam",tab)
dpb
el 10 de En. de 2023
Editada: dpb
el 10 de En. de 2023
" First we have to convert table into cell...."
No, not really. You do have to reference the variable of interest inside the table, though, yes...
Try the following instead...
name=["sam"; "jack"];
age=[20'; 27]; height=[4; 5];
tab=table(name, age, height);
tab(strcmp(tab.name,'sam'),:)
Or, with new string variable functions,
tab(matches(tab.name,'sam'),:)
Ver también
Categorías
Más información sobre Characters and Strings 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!