How to group discontinuous numbers
1 次查看(过去 30 天)
显示 更早的评论
I have a variable of 206*1 ,I would like to separate it. It starts with 100-122.183-xxxx etc.How can I put them to separate groups ?
load('Risk_values.mat');
bar(mediumRiskXValues);
2 个评论
Dyuman Joshi
2024-2-6
What should be the groups?? or which criteria/logic should be followed to categorize values into groups??
采纳的回答
Dyuman Joshi
2024-2-6
load('Risk_values.mat');
whos
idx = cumsum([1;diff(mediumRiskXValues)~=1])
out = accumarray(idx, mediumRiskXValues, [], @(x) {x.'})
3 个评论
Dyuman Joshi
2024-2-6
No, it can not be, because the each cell element has different amount of elements.
In MATLAB, a numeric array or a matrix must have the same number of elements in each row and the same number of elements in each column.
If you try to make a numeric array with different sizes for either row/column, you will get an error -
[1 2 3; 4 5]
However, you can pad the spaces in rows, with NaN, to make them of same size using - https://in.mathworks.com/matlabcentral/fileexchange/22909-padcat
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!