필터 지우기
필터 지우기

Find group number from a range of data that is not fixed

조회 수: 4 (최근 30일)
Zarak kh
Zarak kh 2020년 12월 4일
댓글: Zarak kh 2020년 12월 8일
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 ?
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
Zarak kh
Zarak kh 2020년 12월 4일
Hi Steven,
Thanks for your comment, My question lies in the your third category. I have a set of data that the size in unkown, I divide them into groups of 8 elements. finally I need to find out that a random row-number is in which group number. I hope this could help
Jon
Jon 2020년 12월 4일
I think my answer addresses what you describe

댓글을 달려면 로그인하십시오.

채택된 답변

Jon
Jon 2020년 12월 4일
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
  댓글 수: 3
Jon
Jon 2020년 12월 8일
Good catch, you're right. You should use
groupNo = ceil(x/n)
Zarak kh
Zarak kh 2020년 12월 8일
Thanks for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by