how can I only display all the data?

7 views (last 30 days)
Manav Divekar
Manav Divekar on 30 Jan 2022
Edited: Voss on 30 Jan 2022
from this txt fike how can i just get the data and asign to a variable

Accepted Answer

Voss
Voss on 30 Jan 2022
Edited: Voss on 30 Jan 2022
If your version of MATLAB is R2019a or newer, you can use readmatrix():
filename = 'DHD_10%_sec_T1.txt';
data = readmatrix(filename);
format long
data
data = 20275×3
-0.000050862627887 -0.124530710279942 0.008000000379980 -0.000050862627887 -0.112610071897507 0.008999999612570 -0.000050862627887 -0.098028592765331 0.009999999776483 -0.000050862627887 -0.083013646304607 0.010999999940395 -0.000050862627887 -0.069782592356205 0.012000000104308 -0.000050862627887 -0.059479601681233 0.013000000268221 -0.000050862627887 -0.052053701132536 0.014000000432134 -0.000050862627887 -0.048166055232287 0.014999999664724 -0.000050862627887 -0.047958608716726 0.016000000759959 -0.000050862627887 -0.051448512822390 0.017000000923872
In older versions (or just as an alternative), you can use fscanf():
filename = 'DHD_10%_sec_T1.txt';
fid = fopen(filename);
for i = 1:8 % skip 8 header lines
fgetl(fid);
end
data = reshape(fscanf(fid,'%g'),3,[]).';
fclose(fid);
format long
data
data = 20275×3
-0.000050862627887 -0.124530710279942 0.008000000379980 -0.000050862627887 -0.112610071897507 0.008999999612570 -0.000050862627887 -0.098028592765331 0.009999999776483 -0.000050862627887 -0.083013646304607 0.010999999940395 -0.000050862627887 -0.069782592356205 0.012000000104308 -0.000050862627887 -0.059479601681233 0.013000000268221 -0.000050862627887 -0.052053701132536 0.014000000432134 -0.000050862627887 -0.048166055232287 0.014999999664724 -0.000050862627887 -0.047958608716726 0.016000000759959 -0.000050862627887 -0.051448512822390 0.017000000923872

More Answers (0)

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!