Importing and Exporting to Excel

I am trying to import an Excel file into MATLAB, extract 2 columns of information, then save two columns into a pre-existing file.
For example, the file imported into MATLAB will be similar to this:
_1810 AUDIO WMSE - Underwriting Promo #1 C:\RADIOSPOTS\AUDIO\1810.WAV
2891 AUDIO Shepherd Express - General C:\RADIOSPOTS\AUDIO\2891.WAV_
I want to extract:
_1810 WMSE - Underwriting Promo #1
2891 Shepherd Express - General_
and save in the file below under PSA_num *and *Client Name:
PSA_num Client Name Start_Time End_time Category Script
R124 Special Olympics 4/12/2013 4/12/2014 Environment Hello
R123 Ad Council 4/12/2013 4/12/2013 Educational Hello
R123 Wisconsin 4/13/2013 4/13/2013 Educational Hello

 Akzeptierte Antwort

Image Analyst
Image Analyst am 28 Mai 2013

0 Stimmen

Did you try xlsread() and xlswrite()? If xlswrite is blowing away your existing workbook, then you can try writing it to a worksheet of a different name (e.g. "results" instead of to "sheet1") or you can use Active X: http://www.mathworks.com/support/solutions/en/data/1-QLD4K/index.html?solution=1-QLD4K

7 Kommentare

I have tried both. When I use xlsread the information is in cell arrays. So when i try to use xlswrite like this:
read={psa2 Client};
xlswrie(file, read);
where psa2 is the first column as double and Client is a cell array of the second column, I get the following error.
Error: Object returned error code: 0x800A03EC
I figured it is because "Client" is a cell array. So I tried changing from cell to string, but I was unsuccessful with that.
Don't use read for a variable name - it is a reserved function name. Use something like ca (for cell array) instead. And make sure you spell xlswrite correctly. What does this report
whos file, psa2, Client, ca
Name Size Bytes Class Attributes
file 1x12 24 char
psa2 =
1810
2891
1875
3137
2891
1894
3140
3140
1892
Client =
'WMSE - Underwriting Promo #1'
'Shepherd Express - General'
[NaN]
[NaN]
'Shepherd Express - General'
[NaN]
[NaN]
[NaN]
[NaN]
ca =
[9x1 double] {9x1 cell}
Nada Ismail
Nada Ismail am 28 Mai 2013
I still get the same error
Yeah because you can't do that. You'll need a 9 by 2 cell array. In the first column you'll have to stuff psa2 and in the second column you'll need to stuff Client. Something like this (untested):
ca = cell(9,2); % Initialize.
for row = 1 : 9
ca{row, 1} = psa2(row);
ca{row, 2} = Client{row};
end
xlswrite(filename, ca, 'A1', 'My Results');
Make sure you read and understand the FAQ on cell arrays: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
Nada Ismail
Nada Ismail am 29 Mai 2013
Thanks a lot!
Image Analyst
Image Analyst am 29 Mai 2013
If we're done, please go ahead and mark this as "Answered". Thanks.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by