Borrar filtros
Borrar filtros

Finding a column with specific text

6 visualizaciones (últimos 30 días)
BENJAMIN BUCHDA
BENJAMIN BUCHDA el 15 de Feb. de 2021
Comentada: Star Strider el 15 de Feb. de 2021
I am trying to create a function that takes a array of characters and finds the first column that has a specific input. It seems to work however when I ask have cells with multiple characters an error message saying matrix dimensions must agree. Not sure what I am doing wrong. Any suggestions?

Respuesta aceptada

Star Strider
Star Strider el 15 de Feb. de 2021
I have no clear idea of what the exact problem is, however using strfind or strcmp (or strcmpi) instead of the logical operation with ‘==’ could do what you want.
  3 comentarios
Adam Danz
Adam Danz el 15 de Feb. de 2021
Editada: Adam Danz el 15 de Feb. de 2021
strcmp/strcmpi returns the index number.
If your array is 1D (vector) then you're problem is solved.
If your array is >1D you can use ind2sub to get the column number.
ind = strcmpi(YourArray, subStr);
[~, col] = ind2sub(size(YourArray),find(ind));
Star Strider
Star Strider el 15 de Feb. de 2021
BENJAMIN BUCHDA — Als always, my pleasure!
Adam Danz — Thank you.
.

Iniciar sesión para comentar.

Más respuestas (0)

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!

Translated by