tags:

views:

196

answers:

2

I have an input data in Excel which has 2000 rows and 60 columns.

I want to read this data into MATLAB but I need to to interchange the rows and the column so that the matrix will be 60 rows and 2000 columns. How can I do this in MATLAB, because Excel only has 256 column which cannot hold 2000 columns.

+4  A: 

You just need to transpose it: data = data'

tzaman
Note that you should use the `.'` operator for a simple array transpose, since the `'` operator will perform a complex conjugate transpose if the data values are complex.
gnovice
i did that but i have errors. Let me explain what i amtrying to do.I have a data which is 2000 rows and 60 columns. I am trying to plot labelMap for clustering but my program looks at a column and find i or zero to be able to classify data into this two clusters. But the 1 or zeros are inserted as extra row which makes it 2001 rows and 60 columns. i want to transpose this 2001 as rows so that the program will look at the 2001th column and the perform its classification and plot the label map.But anytime i run it, i have errors
Mola
Here are the errors:Error in ==> showMap at 36 figure,plot(cluster1(:,1),n+1-cluster1(:,2),'^b',cluster2(:,1),n+1-cluster2(:,2),'og');Error in ==> mainfunction at 108 showMap(Map,LabelMap,map_size,data,col);I don't know what? and the figure does not plot.
Mola
My data is here: http://rapidshare.com/files/383549074/data.xls.htmlyou can change it from .xls to .txt to be able to read it with my program.Here are the two programs involved:Mainfunction: http://rapidshare.com/files/383553075/mainfunction.txt.htmlthe showMap function: http://rapidshare.com/files/383553389/showMap.txt.htmlPlease kinly run them and help me see why i keep having the errors aboveThanks
Mola
Can someone just look at my programs for me and see if he/she can see the problem of my error which i am not seeing. I really don't know.Thanks
Mola
@Mola: Please edit your question and paste the code directly there.
tzaman
A: 

To read in the data to MATLAB, start with the xlsread function. Then transpose it, as tzaman showed in his solution.

Your code might look like this:

[filename,path]=uigetfile();
data=xlsread([path,filename]);
data=data';
xlswrite([path,'myfile.xls'],data);

Which would save the transposed data as myfile.xls in the same directory as the original file.

EDIT: Excel 2003 is limited to 256 columns, which is why xlswrite is throwing an error. Have you tried using dlmwrite instead?

Doresoom
BTW, the code Doresoom suggest gives an error which goes thus:??? Error using ==> xlswriteError: Object returned error code: 0x800A03ECi guess excel cannot handle more than 256 column and the number of columns in myfile.xls is supposed to be 2001. How can i solve this problem?
Mola
@Mola: I just double checked and ran my code w/ 2001 columns, no problem. What version of Excel are you using? Also, if xlswrite keeps throwing an error, and you just want access to the data, you can manipulate it in MATLAB after loading it with the first 3 lines of my example.
Doresoom
I want to have it write out. I don't know what i am doing wrong but it gives me error. Am using excel 2003. I still have the same error. When i run the code, it asked me to go to the path where i have the code and i click on the m file and it give the error.??? Error using ==> xlswriteError: Object returned error code: 0x800A03ECError in ==> testing at 4xlswrite([path,'myfile.xls'],data);I created your code as a separate M-file to read and write out my data.Any idea
Mola

related questions