Merging or Combining Rows
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a matrix that looks like this:
86 34
23 59
93 45
(Random numbers) But I want to make it like this:
8634
2359
9345
Basically, making each row of 2 numbers each into 1 number. I'm sure there is a basic solution to this, however I am new to Matlab.
The point of this little exercise is to find the unique number sequence. I tried summing along the rows and using "unique" but the problem was that some rows summed to the same value, even with different numbers. i.e.:
72 34
34 72
These would sum to the same number and one would be removed by "unique", even though their order is different.
I hope this was clear. Thank you!
댓글 수: 0
채택된 답변
Shashank Prasanna
2013년 5월 5일
I am sure there are quick way to solve the unique problem, but you can merge the two numbers by converting them to strings and back:
% If A is your matrix
>> A = [86 34
23 59
93 45
72 34
34 72];
>> B = num2str(A);
>> B(:,3:4) = [];
>> B = str2num(B);
>> unique(B)
추가 답변 (1개)
Roger Stafford
2013년 5월 5일
편집: Roger Stafford
2013년 5월 5일
For your stated purpose you should use 'unique' with the 'rows' option.
To answer your question, however, do the following. This assumes that all the numbers in A are integers somewhere in the interval from 0 to 99.
B = 100*A(:,1)+A(:,2);
댓글 수: 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!