How to import excel file into a specific format in matlab

조회 수: 3 (최근 30일)
Gabriel
Gabriel 2015년 11월 11일
댓글: dpb 2015년 11월 12일
Hi,
It is my first attempt to import an excel file to matlab and I'm having some trouble doing it the way I need.
I have a file consisting of 3 columns:
Sales Item 1 Sales Item 2 and Sales Item 3
each one with 80 lines, so it is something like:
Item 1 Item 2 Item 3
2 4 12
3 8 71
4 42 12
12 31 10
I need to import it into matlab in the following format:
X=[2 4 12;3 8 71;4 42 12;12 31 10]
and so on...
Does anybody know if it is possible?
Thanks in advance !
  댓글 수: 2
Mohammad Abouali
Mohammad Abouali 2015년 11월 11일
편집: Mohammad Abouali 2015년 11월 11일
could you upload a sample Excel file?

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

답변 (2개)

dpb
dpb 2015년 11월 11일
[x,hdr]=xlsread('yourExcelfile.xls');
will leave you with the numeric data in the array x arranged as it is in the spreadsheet and the text headers in hdr
  댓글 수: 4
Gabriel
Gabriel 2015년 11월 11일
It is in N rows of 3 numeric columns.
The thing is: I want it to return the data in the format I described before. I want it to return: [2 4 12;3 8 71;4 42 12; 12 31 10]. All the lines of the file together. It may be because I am completelly new to this, but with your data, I can only get columns if I type 'X, Item 1', for example. I really want it to return the whole lines x columns in the format I described.
A lot of thanks for your help, mate !
dpb
dpb 2015년 11월 12일
Try the newer table data object then...

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


Walter Roberson
Walter Roberson 2015년 11월 12일
>> x = xlsread('cluster_test.xlsx')
x =
2 2 7
4 6 7
6 4 1
121 53 4
2 1 12
Looks like what you need to me.
If it doesn't look like the right format to you then use
mat2str(x)
and see if the printable representation is what you expect.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by