How to check what part of an array isn't scalar?

3 ビュー (過去 30 日間)
Flynn McGuire
Flynn McGuire 2020 年 6 月 25 日
コメント済み: Flynn McGuire 2020 年 6 月 25 日
I keep getting an error from @unique saying a categorical I have array isn't scalar. Is should be, but my data set is huge.
How to I figure out what part is cuasing the error?
Thanks!

回答 (1 件)

the cyclist
the cyclist 2020 年 6 月 25 日
編集済み: the cyclist 2020 年 6 月 25 日
Just to clarify, are you saying that you have a categorical array, you are trying to apply the unique command to that array, and you are getting an error that says the array isn't scalar?
Please post the full error message you are getting.
Is the array too big to put in a MAT file and upload here?
If C is your array, and suppose it has N elements (where N is large), and the line
unique(C)
gives the error you mention. Then you could try unique on, say, the first million rows (or whatever):
unique(C(1:1000000))
and see if that fails. If so, then keep narrowing down:
unique(C(1:500000))
and so on. When it does not give the error, then zoom in on the other part of the array:
unique(C(500001:100000))
etc, to narrow down to a section of the array that is small enough to visually inspect more easily.
  1 件のコメント
Flynn McGuire
Flynn McGuire 2020 年 6 月 25 日
It might be more a problem with splitapply than unique:
column_varnames = {...}
edicu_data = data(ismember(data.mrn,edicu),:);
ed_icu = edicu_data(:, column_varnames);
G = findgroups(edicu_data.mrn);
all_summary_icu = struct();
for i = 1:length(column_varnames)
varname = column_varnames{:, i};
all_summary_ed_icu_demographic.(varname) = splitapply(@unique, ed_icu(:,varname), G);
end
The function 'unique' returned a non-scalar value when applied to the 4th group of data.
To compute nonscalar values for each group, create an anonymous function to return each value in a scalar cell:
@(x1){unique(x1)}
The categories in the 4th group of data are 'yes','no', and <undefined>

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

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by