0

In MATLAB, I have data which looks like this:

    5 7 1 
    5 8 2 
    5 9 3 
    6 7 3 
    6 8 3 
    6 9 2 

where each column is an array (e.g. x = [5; 5; 5; 6; 6; 6]). I want the data to be put in matrix form in the following manner:

        7    8    9
    5   1    2    3
    6   3    3    2

Any suggestions?

Eitan T
  • 32,660
  • 14
  • 72
  • 109
  • What would be A(1,1) if A is your output matrix? NaN? Zero? – Andrey Rubshtein May 15 '12 at 15:08
  • Can you explain the output matrix in more detail? – Eitan T May 15 '12 at 15:11
  • The output matrix does not matter whether it is a= [output] or if it is an array a= [5; 6], b= [7; 1; 3] etc. I just need the output so that i can copy and paste onto excel – Walid Masud May 15 '12 at 15:15
  • And Andrey, it doesn't matter if A(1,1) is 0, I just want to know if this can be done using MATLAB, thanks – Walid Masud May 15 '12 at 15:17
  • Nearly everything is possible with MATLAB, but I fail to understand what is it that you want to do with your data. – Eitan T May 15 '12 at 15:18
  • http://stackoverflow.com/questions/9617348/reshape-three-column-data-frame-to-matrix my question is the exact same as this one, perhaps it would be easier to understand from this question. Instead of using variables in my case I am using numbers. I was wondering if this process can be done on MATLAB – Walid Masud May 15 '12 at 15:21

1 Answers1

3

Is this what you need?

>> x =[5 7 1
       5 8 2
       5 9 3
       6 7 3
       6 8 3
       6 9 2];
>> rowlabels = unique(x(:,1))
rowlabels =
     5
     6
>> collabels = unique(x(:,2))'
collabels =
     7     8     9
>> data = reshape(x(:,3),numel(collabels),numel(rowlabels))'
data =
     1     2     3
     3     3     2
Sam Roberts
  • 23,951
  • 1
  • 40
  • 64
  • http://stackoverflow.com/questions/9617348/reshape-three-column-data-frame-to-matrix my question is similar to this one, except instead of using variables, in my case I am using values. Thank you for the input. – Walid Masud May 15 '12 at 15:25