Write ".m" matlab code files to excel
32 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Glen Rodrigues
am 17 Aug. 2020
Kommentiert: Glen Rodrigues
am 17 Aug. 2020
Hi, I have currently designed a simulation tool on matlab which uses a .m input file. The file basically contains parameters and data required for simulation. The results generated are then written to excel file. What I was wondering is if it is possible to write this input file , which is a ".m" code file to excel? basically copy the contents of this m file as is and paste it to excel. Is there a functon or command I could use to do this?
Thank You In Advance
0 Kommentare
Akzeptierte Antwort
Dana
am 17 Aug. 2020
A few things. First of all, I want to double-check that the file you're talking about is indeed an .m file. .m files are MATLAB scripts/functions, i.e., files which contain instructions telling MATLAB to do things. .mat files, meanwhile, are files used to store MATLAB data.
If indeed it's the case that you're storing data/parameters in an .m file, then step 1 is to save that information properly to a .mat file, and step 2 is to never store data/parameters in an .m file ever again. To do step 1, load up all that info into MATLAB variables in your workspace, and then use the save command to save it to a .mat file. From then on, you just need to use the load command to load up that data in MATLAB. Step 2, meanwhile, is self-explanatory.
Now, assuming you've got your data in a .mat file, to convert to an Excel file, you'll want to read up on xlswrite.
Finally, if you literally want the text in an .m file to be copied to an Excel file, the easiest thing would be to literally just open the .m file in the editor, highlight what you want, copy, and then paste in Excel. I can't really see why you'd ever want to do something like that, but hey, stranger things have happened I guess.
6 Kommentare
Dana
am 17 Aug. 2020
This is much easier converting to a .txt file than an Excel file. Excel files, like .mat files, are best for storing data, but you're talking about storing lines of code from an .m file, which is properly interpreted as text.
So here's what you could do:
mfilename = 'input.m'; % name of .m file you want to copy
txtfilename = 'input.txt'; % name for the .txt file you'll create (WITH FILE EXTENSION)
copyfile(mfilename,txtfilename); % tell MATLAB to copy the .m file 'mfilename'
% and name it 'txtfilename'
Now you have a copy of the .m file, but saved as a plain text file.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!