0

This is my program:

x= 9;
fprintf(' a z \n _ _ \n');
for a = 0:4
  z =x+a;
fprintf(' %d %d\n',a,z);

end

how can i convert the output into excel spreedsheet? or file?

1 Answer 1

1

The easiest way to get data from Matlab into Excel is writing to a plain text .csv file, then importing that into Excel. To do this, simply open a file

fileID = fopen('mydata.csv','w');

change the fprintf statements to write to that file

x= 9;
fprintf(fileID, ' a, z \n _, _ \n');
for a = 0:4
    z =x+a;
    fprintf(fileID, ' %d, %d\n',a,z);
end

and make sure to close the file when you are done

fclose(fileID);

Import this into Excel and you can save it as an xls file.

Sign up to request clarification or add additional context in comments.

6 Comments

You should note that CSV stands for comma-separated-value, and so columns are delimited by commas. I don't see any commas written in your code.
true, fixed. Excel would still understand the file, but it should probably be a .txt
how can i save it? as .m?
@Raldenors - The code above already saves it to file. You should see a mydata.csv file once you finish with the above code.
@Urs - Good! Now you get my +1 :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.