MATLAB: If statement with table

nested if statement in table

I am a developmental psychologist and use Matlab for data analyses. I am not proficient at all in writing scripts from scratch, so any help is much appreciated. I have 2 columns in a table. I want to modify the contents of the 1st column depending on the 2nd column.
For example,
C = {'bgin' 'NAN'; 'resp' '';'TRSP' '1'; 'TRSP' '0'};
If row1 = 'TRSP' and row2 = '1' --> row1 should be changed to 'cor'.
If row1 = 'TRSP' and row2 = '0' --> row1 should be changed to 'inc'.
Else row1 = row1 (i.e. no change)
In other words, referring to the example above, I need C to look as follows at the end:
C = {'bgin' 'NAN'; 'resp' '';'cor' '1'; 'inc' '0'};
And I need these logical statements to apply to all the rows (~1000) in the table.
I'd very much like to do this in Matlab as I have more than 1500 files to change and at least know how to loop through files in Matlab.
Thanks in advance!

Best Answer

C is not a table it's a cell array
C = {'bgin' 'NAN'; 'resp' '';'TRSP' '1'; 'TRSP' '0'}
idx1=ismember(C(:,1),'TRSP') & ismember(C(:,2),'1')
idx2=ismember(C(:,1),'TRSP') & ismember(C(:,2),'0')
C(idx1,1)={'cor'}
C(idx2,1)={'inc'}