Error using discretize: Bin edges must be a vector that is real, numeric or logical, and monotonically increasing.
6 次查看(过去 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!