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!