- Is group 1 always the numbers less than 9 and group 2 is everything else?
- Is group 1 always the first half of the data and group 2 the second half?
- Do you divide the data into groups that each contain 8 elements?
- Do you divide the data into groups based on the smallest multiple of 8 that they are less than or equal to?
Find group number from a range of data that is not fixed
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I need to solve a problem like below. I have a matrix with 1 column, with unknown number of rows. I have a random number for number of row, and I need to find out that which group is this row in.
Imagine I have this data and I need to found out that row number=10 is in which group ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/445188/image.png)
My main concern is since I do not know how many groups do I have (inittially unkown) , how should I modify my code?
number_row=randperm(16,1)
if number_row<8
disp("group 1")
else
disp ("group 2")
end
Thanks in advance for help
3 Kommentare
Akzeptierte Antwort
Jon
am 4 Dez. 2020
Are your groups always as you show in your example? That is, group 1 = 1,2,..8 group 2 = 9, 10,..16, group 3 = 17,18, ...24 ?
In this case you can just use
n = 8; % number of elements in group
maxVal = 290 % put your value here
x = randperm(maxVal,1)
groupNo = floor(x/n) + 1
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!