If statement with table
5 ビュー (過去 30 日間)
古いコメントを表示
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!
採用された回答
Azzi Abdelmalek
2016 年 7 月 24 日
編集済み: Azzi Abdelmalek
2016 年 7 月 24 日
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'}
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!