Error using discretize: Bin edges must be a vector that is real, numeric or logical, and monotonically increasing.

6 vues (au cours des 30 derniers jours)
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).

Réponse acceptée

Voss
Voss le 15 Déc 2022
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)
128 138 194 617 76 92 155 978 62 68 124 152 67 71 83 155 67 79 122 433 199 208 269 0 68 77 89 143 83 88 196 322 71 76 123 180 135 194 256 692 133 149 196 241 67 71 125 186 92 134 193 373 121 142 242 363 65 70 91 200 35 62 151 1162 73 128 198 1171 26 34 80 335 71 88 88 0 79 85 142 370 87 93 145 188 76 80 0 0 83 129 198 428 86 90 133 249
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 commentaires
lil brain
lil brain le 15 Déc 2022
You're right it does work. Something was off with my version. Thanks!
Steven Lord
Steven Lord le 15 Déc 2022
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Identification dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by