MATLAB Answers

Reading a matrix from a .txt file

1 view (last 30 days)
Giovanni Filomeno
Giovanni Filomeno on 16 Jan 2021
Commented: Ive J on 17 Jan 2021
Good morning everyone. I'm trying to import in matlab a matrix from a text file. In my file, there are only two columns of values, separated by a single space. Here I report the first two rows of the file:
("Time Step" "Vertex Average X Velocity")
439 -0.1588049829006195
440 -0.157896234563214
I tried to import the matrix through
but I ony obtain
ans =
But if I put a comma between the two columns, Matlab reads the matrix correctly. Is there a way to import this matrix without putting commas between every column?

Sign in to comment.

Accepted Answer

Ive J
Ive J on 17 Jan 2021
Try this
myMat = readmatrix('myfile.txt', 'delimiter', ' ');

More Answers (0)

Community Treasure Hunt

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

Start Hunting!