Borrar filtros
Borrar filtros

How to group discontinuous numbers

1 visualización (últimos 30 días)
Kaleesh
Kaleesh el 6 de Feb. de 2024
Comentada: Kaleesh el 6 de Feb. de 2024
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 comentarios
Dyuman Joshi
Dyuman Joshi el 6 de Feb. de 2024
What should be the groups?? or which criteria/logic should be followed to categorize values into groups??
Kaleesh
Kaleesh el 6 de Feb. de 2024
The 206 values inside mat file is like 100-123 continuous numbers then it starts like 182-193,365,522-530.So to group these continuous numbers

Iniciar sesión para comentar.

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 6 de Feb. de 2024
load('Risk_values.mat');
whos
Name Size Bytes Class Attributes ans 1x40 80 char cmdout 1x33 66 char mediumRiskXValues 206x1 1648 double
idx = cumsum([1;diff(mediumRiskXValues)~=1])
idx = 206×1
1 1 1 1 1 1 1 1 1 1
out = accumarray(idx, mediumRiskXValues, [], @(x) {x.'})
out = 17×1 cell array
{[ 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123]} {[ 182 183 184 185 186 187 188 189 190 191 192 193]} {[ 365]} {[ 522 523 524 525 526 527 528 529 530]} {[ 926 927 928 929 930 931 932 933 934 935 936 937]} {[ 1095 1096 1097 1098 1099 1100 1101 1102 1103]} {[ 1201 1202 1203 1204]} {[ 1289 1290 1291 1292 1293 1294]} {[ 1361 1362 1363 1364 1365]} {[ 1438 1439 1440]} {[ 1525]} {[ 1634 1635 1636 1637 1638 1639 1640]} {[ 1872 1873 1874 1875 1876 1877 1878 1879]} {[ 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027]} {[ 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141]} {[2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 … ] (1×40 double)}
  3 comentarios
Dyuman Joshi
Dyuman Joshi el 6 de Feb. de 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]
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
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
Kaleesh
Kaleesh el 6 de Feb. de 2024
Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by