Merging or Combining Rows
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Shashank Prasanna
am 5 Mai 2013
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)
Weitere Antworten (1)
Roger Stafford
am 5 Mai 2013
Bearbeitet: Roger Stafford
am 5 Mai 2013
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 Kommentare
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!