I need to create a text file using numeric data (a basic 4x4 matrix). (I'm very new to this)

I really need to get [10 5 7 9; 11 8 0 5; 17 34 67 89; 87 54 32 98] as a text file named mydata.txt in the current directory and then use the "load' function to read the file and create a variable named mydata containing that matrix.

1 Comment

The MATLAB documentation is really good: it has clear explanation and working examples:
Have you made any attempt to solve this simple task yourself? If we do your homework for you, do we get the course grades as well ?

Sign in to comment.

 Accepted Answer

dlmwrite('mydata.txt', [10 5 7 9; 11 8 0 5; 17 34 67 89; 87 54 32 98], '\t');
mydata=load('mydata.txt');
Or, unless there's another need for the file you really don't need it at all, just create the array on the fly and go on with whatever:
mydata=[10 5 7 9; 11 8 0 5; 17 34 67 89; 87 54 32 98];
Or, of course, just use a text editor such as the one builtin to Matlab to create the file externally.

More Answers (0)

Tags

Asked:

on 19 Sep 2016

Edited:

dpb
on 19 Sep 2016

Community Treasure Hunt

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

Start Hunting!