필터 지우기
필터 지우기

Column Number Matching

조회 수: 1 (최근 30일)
charles atlas
charles atlas 2012년 6월 20일
I have two columns of data stored in array "A" one is random numeric data and the other is just numbers 1, 2, 3, 4, or 5. I want to look at A and take any row that has ones in the second column and store it in array R1, take any row that has twos in the second column and store it in array R2, take any row that has threes in the second column and store it in array R3, take any row that has fours in the second column and store it in array R4, and finally I want to take any row that has fives in the second column and store that data in an array "R5"
Thanks, Charles
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 6월 20일
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

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

채택된 답변

Image Analyst
Image Analyst 2012년 6월 20일
As long as you only have a few variables, such as 5, then you can do it simply in one line of code per number (variable):
m = randi(5, [10 2]) % Create sample data.
% Get the second column so we can check its values.
secondColumn = m(:,2)
% Create R1 through R5
R1 = m(secondColumn==1, 1)
R2 = m(secondColumn==2, 1)
R3 = m(secondColumn==3, 1)
R4 = m(secondColumn==4, 1)
R5 = m(secondColumn==5, 1)
  댓글 수: 1
charles atlas
charles atlas 2012년 6월 21일
That worked perfectly, thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by