Read Numbers from .dat file in the format of a 3d matrix

2 visualizzazioni (ultimi 30 giorni)
Hi, I have a .dat file as below:
1, 2, 4, 2, 4
3, 4, 6, 1, 5
...
They are 40 numbers, 8 lines and 5 columns.
Now,
I want to read it by matlab as a 3d matrix: 4*2*5
If you suggest textscan please give me some hints how to use it. Thanks alot!

Risposta accettata

Jan
Jan il 7 Ott 2013
There are many different versions to reshape the data to 4x2x5. Perhaps you want:
fid = fopen(FileName, 'r');
if fid == -1, error('Cannot open file for reading.'); end
data = fscanf(fid, '%g,%g,%g,%g,%g', [5, Inf]);
data = reshape(transpose(data), [4,2,5])
fclose(fid);

Più risposte (0)

Categorie

Scopri di più su Data Import and Analysis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by