필터 지우기
필터 지우기

Write ".m" matlab code files to excel

조회 수: 37 (최근 30일)
Glen Rodrigues
Glen Rodrigues 2020년 8월 17일
댓글: Glen Rodrigues 2020년 8월 17일
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

채택된 답변

Dana
Dana 2020년 8월 17일
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
Dana
Dana 2020년 8월 17일
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.
Glen Rodrigues
Glen Rodrigues 2020년 8월 17일
Yep, even I was thinking the same. Was just going through the support page for copyfile command and like you said sounds more reasonable to convert to text file rather than excel.
Thank you :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by