How to group discontinuous numbers
2 views (last 30 days)
Show older comments
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 Comments
Dyuman Joshi
on 6 Feb 2024
What should be the groups?? or which criteria/logic should be followed to categorize values into groups??
Accepted Answer
Dyuman Joshi
on 6 Feb 2024
load('Risk_values.mat');
whos
idx = cumsum([1;diff(mediumRiskXValues)~=1])
out = accumarray(idx, mediumRiskXValues, [], @(x) {x.'})
3 Comments
Dyuman Joshi
on 6 Feb 2024
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
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!