Error using discretize: Bin edges must be a vector that is real, numeric or logical, and monotonically increasing.
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
lil brain
el 14 de Dic. de 2022
Comentada: Steven Lord
el 15 de Dic. de 2022
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 comentarios
Respuesta aceptada
Voss
el 15 de Dic. de 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)
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 comentarios
Steven Lord
el 15 de Dic. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Contour Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!