Using XLSWRITE with multiple arrays?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a bunch of arrays which i need to put into an excel spreadsheet. There are 3 and they have to be put into column A, B and C respectively. How do i do this? xlswrite('CarData.xlxs','Sheet1','Model') tried this was just a mess.
>> load carbig.mat
>> Model=xlsread('Model')
Error using xlsread (line 139)
XLSREAD unable to open file 'Model'.
File 'Model' not found.
>> xlsread('Model')
Error using xlsread (line 139)
XLSREAD unable to open file 'Model'.
File 'Model' not found.
>> xlswrite('CarData.xlxs','Model')
>> xlswrite('CarData.xlxs','Sheet1','a','Model')
Warning: Added specified worksheet.
> In xlswrite>activate_sheet (line 300)
In xlswrite/ExecuteWrite (line 266)
In xlswrite (line 220)
Error using xlswrite (line 226)
The specified data range is invalid or too large to write to the specified file format. Try writing to an XLSX file and use Excel
A1 notation for the range argument, for example, ‘A1:D4’.
>> xlswrite('CarData.xlxs','Sheet1',,'Model')
xlswrite('CarData.xlxs','Sheet1',,'Model')
↑
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
>> xlswrite('CarData.xlxs','Sheet1','Model')
Warning: Added specified worksheet.
> In xlswrite>activate_sheet (line 300)
In xlswrite/ExecuteWrite (line 266)
In xlswrite (line 220)
0 commentaires
Réponses (2)
dpb
le 26 Nov 2017
xlswrite('CarData.xlxs',[A B C])
presuming A, B, C are column vectors of same size as are the variables in the carbig dataset altho those are not their names so you'll needs must use the real ones.
One at at time could be
xlswrite('CarData.xlxs',A,1,'A1')
xlswrite('CarData.xlxs',B,1,'B1')
...
altho would be quite slow that way as xlswrite opens and closes the spreadsheet every time and the ActiveX/COM interface is quite overhead-intensive already.
Read/study the documentation more thoroughly to follow the required syntax.
2 commentaires
Image Analyst
le 26 Nov 2017
Modifié(e) : Image Analyst
le 26 Nov 2017
Sean, one problem was that you put Model inside single quotes when you passed it to xlswrite - that made a string instead of sending the variable itself into xlswrite(). And all your character arrays, like Model and Origin etc., should be cell arrays, not character arrays, otherwise it will put each letter into its own cell in Excel.
dpb
le 26 Nov 2017
Modifié(e) : dpb
le 26 Nov 2017
Amongst others...none of the cases OP tried have the arguments in the order specified by the documentation, even accounting for misplaced/uneeded quotes. The data array/element argument follows immediately after the filename, subsequently with optional sheet, range.
Walter Roberson
le 26 Nov 2017
According to the workspace summary, your Model is a 406 x 36 char array. The methods other people are showing will not be able to mix that together properly.
data = [cellstr(Model), num2cell(Model_Year), num2cell(MPG)]; %build cell array
xlswrite('CarData.xlxs', data, 'Sheet1') %data first then sheet
0 commentaires
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!