find the row and column value of a specific value in cell array
38 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Elysi Cochin
el 13 de Abr. de 2021
Comentada: Rik
el 13 de Abr. de 2021
i have a cell array with values
cellarr = {'a','b','c',3,5;'b',5,'a',[],[];'a','c',3,'a',4;'b','a','c','c',3};
i wanted to find the location where a particular number or string occurs
for example i want to get the location where the number = 3
so my expected output is
1st row 3rd column
3rd row 3rd column
4th row 5th column
[row,col] = find(___)
i want both the row and column position as it comes for find function
find not working with cell array
3 comentarios
Xingwang Yong
el 13 de Abr. de 2021
After using find(), you just need to convert the linear index into row and col index, see ind2sub
Respuesta aceptada
Rik
el 13 de Abr. de 2021
You need to use a bit of trickery to use find (ismember will not work normally either).
cellarr = {...
'a','b','c', 3 ,5;...
'b', 5 ,'a',[] ,[];...
'a','c', 3 ,'a',4;...
'b','a','c','c',3};
val=3;
[row,col] = find(cellfun(@(x) isequal(val,x),cellarr));
[row,col]
2 comentarios
Elysi Cochin
el 13 de Abr. de 2021
Editada: Elysi Cochin
el 13 de Abr. de 2021
Rik
el 13 de Abr. de 2021
This is the default order for find, but you can use sort (and its second output) to sort on row instead of column.
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion 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!