Export Data to excel
Show older comments
I have a lot of .csv files to analyse and have opted to use matlab instead of excel to perfrom the analysis, however, I would like the results from this analysis to be stored in an excel file. I have created a matlab file for each .csv file and want the results from each script to be exported to excel. I opted to operate this way so I did not have to use dynamically assigned variable names.
Could you please help with code that I could add to my script which will add my results to a new row in an excel spreadsheet?
Thank you in advance.
Max
3 Comments
Bob Thompson
on 25 Feb 2021
Do you need to read each csv file in an individual script? It would be much easier to just export to Excel once.
Operating MATLAB within excel is certainly possible, but I think the easiest way to append a line of data to an existing excel sheet is to read in the data with a command like xlsread or readtable, append your data to the end of the array, and write the data back into excel with xlswrite or writetable.
Maxwell MacFarlane
on 25 Feb 2021
Bob Thompson
on 25 Feb 2021
You can export to a specific range with xlswrite, but I don't know an easy way to determine what the next empty row within a file is. The options that I know of are the following:
1) You can detect whether a cell in excel is filled while the file is open in the actxserver, but then you might as well just do this project in VBA.
2) You can read the existing data in the file into a variable, determine the length, and generate a range based on that value, but then you might as well do what I suggested before.
3) If you are performing the operation on all of the csv files in one script you can keep a counter and generate the appropriate excel range based on that counter. This is certainly a functional option, but you would be better off keeping all of your data from your csvs in one array, and just printing once.
There may be a way to look for empty cells that I don't know about, but I can't tell you what it is, because I don't know about it.
Answers (0)
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!