How to apply efficient if-else statements in a big data cell array
1 回表示 (過去 30 日間)
古いコメントを表示
I have a cell array of 3 columns. Based on the different joint values of 2nd and 3rd columns, I would like to assign a number to the values of first column. for example:
a x z
b y z
c x y
d y z
for x&z I assign 1 to a, for y&z I assign 2 to b and d, for x&y I assign 3 to c. Well, I can do it within a for-loop and some if-else statements. But the document is too big and this is a bit slow. Does anyone know about an efficient and fast way to do it so?
Many thank, Shima
回答 (1 件)
Jos (10584)
2016 年 3 月 25 日
編集済み: Jos (10584)
2016 年 3 月 25 日
It is a cell array, but each cell has a single number? Then you might be better of converting it to numbers first:
N = cell2mat(C) ;
N(N(:,2)==x & N(:,3)==z, 1) = 1 ;
N(N(:,2)==y & N(:,3)==z, 1) = 2 ;
N(N(:,2)==x & N(:,3)==y, 1) = 3 ;
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!