Answer to Question #6376 in MatLAB | Mathematica | MathCAD | Maple for Lori

Question #6376
Write a script that will load data from a file into a matrix. I am confused on how to load data files and call functions in matlab.
1
Expert's answer
2012-02-10T08:01:48-0500
Suppose you have a file "mydata.txt" with the following contents

1 2 3
4
5 6 7 8
9 10 11 12

So here are numbers separeted by spaces '
'
Then the command

M = dlmread('mydata.txt',' ')

will read all
the file into the matrix M and print

M =

1 2 3
4
5 6 7 8
9 10 11 12


The first
argument of the command 'dlmread' is the file name, and the second one is the
separator of numbers.
If you numbers are separeted by tabsm, or commas use
the commands

M = dlmread('mydata.txt','\t')

or

M =
dlmread('mydata.txt',',')

respectively.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS