How to import excel file into a specific format in matlab
古いコメントを表示
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
2015 年 11 月 11 日
編集済み: Mohammad Abouali
2015 年 11 月 11 日
could you upload a sample Excel file?
Gabriel
2015 年 11 月 11 日
回答 (2 件)
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
2015 年 11 月 11 日
dpb
2015 年 11 月 11 日
If, as you describe, the Excel file is N rows of 3 numeric columns, then it will work to return it in that shape...
>> [x,txt]=xlsread('gabe.xls')
x =
2 4 12
3 8 71
4 42 12
12 31 10
txt =
'Item 1' 'Item 2' 'Item 3'
>>
If, otoh, you have all the data as text in a single column of cells, it's probably easiest to fix the spreadsheet instead.
Gabriel
2015 年 11 月 11 日
dpb
2015 年 11 月 12 日
Try the newer table data object then...
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.
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!