Saving data on .m file

15 views (last 30 days)
Anup Khadka
Anup Khadka on 15 Dec 2021
Answered: Walter Roberson on 15 Dec 2021
The homework question orders me to save my datas on .m file, without replacing the previous saved datas. i saved it as per the question and i see some kind of parse error
Can i get rid of it?

Answers (1)

Walter Roberson
Walter Roberson on 15 Dec 2021
That is not necessarily an error. The data could be retrieved from the file by using load() or readmatrix()
You would not typically save data to a .m file as .m files are normally for executable code.
If the expectation is that you are to create executable code, then you need to save the data in the form of an assignment statement. Something like
fid = fopen(etc etc);
fprintf(fid, 'ag = [\n');
now fprintf a and g
fprintf(fid, '];\n');
You would then do something similar for a1 g1, except giving it a different variable name, such as 'a1g1 = '

Categories

Find more on Data Import and Export 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!