Error using discretize: Bin edges must be a vector that is real, numeric or logical, and monotonically increasing.
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have the following code:
N = numel(newdata);
split_newdata = cell(1,N);
split_newdata_mean = cell(1,N);
for ii = 1:N
temp = reshape([newdata{ii}{:}],[],2);
idx = discretize(temp(:,1),[0 split_points_noID(ii,:) Inf]);
split_newdata{ii} = groupsummary(temp(:,2),idx,@(x){x});
split_newdata_mean{ii} = cellfun(@(x)mean(x,'omitnan'),split_newdata{ii});
end
But I continue to get the error:
Error using discretize
Bin edges must be a vector that is real, numeric or logical, and monotonically increasing.
Error in CRM_analysis (line 167)
idx = discretize(temp(:,1),[0 split_points_noID(ii,:) Inf]);
I have attached the two files here. Essentially I am trying to split the individual cells in newdata according to the cut-off points in the cows of split_points_noID. If that makes sense.
Thank you for your help!
** EDIT:
I get a really weirdly incomplete split_newdata (see file).
0 件のコメント
採用された回答
Voss
2022 年 12 月 15 日
load newdata
load split_points_noID
Not every row of split_points_noID is monotonically increasing, because there are some trailing zeros sometimes
disp(split_points_noID)
To fix the code to work for this situation, remove the zeros from each row of split_points_noID, using logical indexing or nonzeros, before you use it in discretize:
N = numel(newdata);
split_newdata = cell(1,N);
split_newdata_mean = cell(1,N);
for ii = 1:N
temp = reshape([newdata{ii}{:}],[],2);
idx = discretize(temp(:,1),[0 nonzeros(split_points_noID(ii,:)).' Inf]); % nonzeros
% idx = discretize(temp(:,1),[0 split_points_noID(ii,split_points_noID(ii,:) > 0) Inf]); % logical indexing
split_newdata{ii} = groupsummary(temp(:,2),idx,@(x){x});
split_newdata_mean{ii} = cellfun(@(x)mean(x,'omitnan'),split_newdata{ii});
end
4 件のコメント
Steven Lord
2022 年 12 月 15 日
If you encounter this problem again I would set an error breakpoint and run your code. When MATLAB stops at the breakpoint, ask:
issorted(split_points_noID(ii, :))
If that returns false, you need to investigate what's on row ii of split_points_noID.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!