Accumarray error: First input SUBS must contain positive integer subscripts.

28 ビュー (過去 30 日間)
Hello,
The accumarray function is causing me problems - the error is embedded within the question. Attached you find a sample file and below you find the piece of code I wrote:
temp_raw_JE50=X0012_50(:,20)-X0012_50(:,17); % raw overall JE50
temp_AO50=ismember(X0012_50(:,13),0); % AO trials (0's) in col. 13 of temp_file_50
temp_raw_JE50AO= accumarray(temp_raw_JE50,temp_AO50); % raw JE50 for AO trials only
Could you please be so kind as to help me?
Bianca

採用された回答

Sean de Wolski
Sean de Wolski 2016 年 6 月 27 日
[uval,~,subs] = unique(temp_raw_JE50);
accumarray(subs,vals)
You most likely want to accumulate by the unique values. Since these aren't necessarily positive integer indices, use unique first and pass the indices into accumarray.
  1 件のコメント
Bianca Elena Ivanof
Bianca Elena Ivanof 2016 年 6 月 28 日
編集済み: Bianca Elena Ivanof 2016 年 6 月 28 日
Thank you - I've tried your option but the script keeps crashing (new error: 'Second input VAL must be a vector with one element for each row in SUBS, or a scalar.'), partly because I can't understand why you use [uval,~,subs] in the example above, so I may not be using it correctly - I know uval and subs refer to the values that come in brackets after accumarray, but I'm missing the big picture.
Is vals the same with uval?
Moreover, would accumarray(subs,vals) replace the accumarray(temp_raw_JE50,temp_AO50) in my script above or accumarray(subs,vals) comes before ismember and accumarray in my script?
Could you please be so kind as to explain?

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2016 年 6 月 28 日
[uval,~,subs] = unique(X0012_50(:,20)-X0012_50(:,17));
temp_raw_JE50AO = accumarray(subs,~X0012_50(:,13));
out = [uval, temp_raw_JE50AO];
  4 件のコメント
Bianca Elena Ivanof
Bianca Elena Ivanof 2016 年 6 月 29 日
thank you.
Sean de Wolski
Sean de Wolski 2016 年 6 月 30 日
Look at the documentation for examples and descriptions of what the pieces are:
doc unique

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by