Skip to main content

9.8) Writing Spreadsheet Data


    • Matlab function "xlswrite" is used to write Excel spreadsheets
    • The main syntax is as follows:

[matlab]
>> xlswrite(filename, A) % writes A to the first worksheet
>> xlswrite(filename, A, sheet) % write A to the worksheet named "sheet"
[/matlab]

[matlab]
>> [ndata,text,alldata]=xlsread('dino_data.xlsx');
[/matlab]
We don't need all of this numerical data, so let's copy some columns and save to a new Excel spreadsheet. Looking at the alldata cell array within the workspace, we can see that we have 15 columns of data and 37 rows. Let's just save the first 7 columns. We can do this as follows:
[matlab]
>> outputdata=ndata(:,1:7);
>> xlswrite('output.xlsx', outputdata)
[/matlab]
We could have easily done some calculations on the data.