for loop to control cellarray whether it is changing or not.

1 回表示 (過去 30 日間)
sermet
sermet 2014 年 5 月 14 日
回答済み: Andrei Bobrov 2014 年 5 月 14 日
ids=[{'100'};{'100'};{'100'};{'p200'};{'p200'};{'p300'};{'p300'};{'pp400'};{'pp400'}]; %cell
data=[100;110;120;130;140;150;160;170;180]; %double
%I wanna determine which rows are same in ids and where changing is starting, then I need to compute this algorithm like that;
a_100=(100+110+120); %they belongs '100'
a_p200=(130+140); %for 'p200'
a_p300=(150+160); %for 'p300'
a_pp400=(170+180); %for pp400
%how can I perform this calculation with loop w.r.t ids cellarray, like a(i)?

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 5 月 14 日
[a,~,c] = unique(ids);
out = [strcat('a_',a),num2cell(accumarray(c,data))];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by