enea19
enea19

Reputation: 123

Finding the row and column for a string in an array in MATLAB

I have the following array:

A = {'E1_02' nan nan nan nan nan;
'Time'  'Force' 'Stress'    'Stroke'    'Ext.1' 'Width1';
'sec' 'N' 'N/mm2'   'mm'    'mm'    'mm'}

which gives

{'E1_02'}    {[  NaN]}    {[   NaN]}    {[   NaN]}    {[  NaN]}    {[   NaN]}
{'Time' }    {'Force'}    {'Stress'}    {'Stroke'}    {'Ext.1'}    {'Width1'}
{'sec'  }    {'N'    }    {'N/mm2' }    {'mm'    }    {'mm'   }    {'mm'    }

This is the start of a very long .csv with data in every column. I would like to find the row and column indices of one of the strings, for example ' Stress', because then I would like to extract the data in that column. I tried find but from what I understand it just check if the string is present in a row or column but does not return the indices of the string's location. What I would like is something like

What string do you want?: ' Stress'
Search through array...
Here are the coordinates for that string: [row column] = [3 2]

Should I make a loop that checks every row and column for the string and then use those as the indices? Or did I misunderstand the way find works?

Upvotes: 0

Views: 86

Answers (1)

Jorge Pérez
Jorge Pérez

Reputation: 96

You could use:

[row, col] = find(strcmp(A,'Stress'))

Upvotes: 1

Related Questions