how I can remove head of file

1 view (last 30 days)
sherek
sherek on 10 Jun 2019
Answered: Shubham on 8 Oct 2024
I have the following code:
fid = fopen('h.csv', 'rt');
for i = 1 : 4 : size( h,1 )
disp( h( i : i + 3,: ) )
disp(['[*,*,' num2str((i + 3)/4) ']: 1 2 3 4 5 6 7 8 9 10:='])
end
The out put is :
VarName1 VarName2 VarName3 VarName4 VarName5 VarName6 VarName7 VarName8 VarName9 VarName10 VarName11
________ ________ ________ ________ ________ ________ ________ ________ ________ _________ _________
51.6 -150.72 -2.0019 103.65 -70.626 -22.092 66.056 -40.393 0.16829 10.898 ""
106.4 -295.17 -64.931 324.57 -238.19 -82.353 345.96 -384.93 255.54 -100.14 ""
107.6 -289.44 -88.518 357.14 -262.29 -72.936 341.1 -378.48 244.79 -93.139 ""
112.5 -294.12 -115.59 405.77 -297.5 -71.468 371.77 -416.44 271.83 -104 ""
[*,*,74]: 1 2 3 4 5 6 7 8 9 10:=
VarName1 VarName2 VarName3 VarName4 VarName5 VarName6 VarName7 VarName8 VarName9 VarName10 VarName11
________ ________ ________ ________ ________ ________ ________ ________ ________ _________ _________
50.9 -148.24 -2.0019 100.41 -67.933 -16.936 47.722 -11.042 -30.068 30.077 ""
118.6 -315.43 -103.4 391.24 -278.28 -80.563 345.19 -351.99 200.75 -59.592 ""
120.2 -324.12 -94.002 385.69 -274.01 -92.952 370.64 -388.75 231.94 -76.445 ""
107.1 -276.4 -117.42 390.35 -276.5 -83.964 368.85 -400.59 251.91 -90.159 ""
[*,*,75]: 1 2 3 4 5 6 7 8 9 10:=
VarName1 VarName2 VarName3 VarName4 VarName5 VarName6 VarName7 VarName8 VarName9 VarName10 VarName11
________ ________ ________ ________ ________ ________ ________ ________ ________ _________ _________
what I should do do remove variables's name and this horizontal line?

Answers (1)

Shubham
Shubham on 8 Oct 2024
Hey Sherek,
I believe that you have not provided the complete code snippet as the variable 'h' is not defined. Since your dataset appears to be having only numerical values, I recommend you to use the readmatrix function:
fid = fopen('h.csv', 'rt');
h = readmatrix('h.csv');
disp( h( 1 : 4,: ) );
51.6000 -150.7200 -2.0019 103.6500 -70.6260 -22.0920 66.0560 -40.3930 0.1683 10.8980 NaN 106.4000 -295.1700 -64.9310 324.5700 -238.1900 -82.3530 345.9600 -384.9300 255.5400 -100.1400 NaN 107.6000 -289.4400 -88.5180 357.1400 -262.2900 -72.9360 341.1000 -378.4800 244.7900 -93.1390 NaN 112.5000 -294.1200 -115.5900 405.7700 -297.5000 -71.4680 371.7700 -416.4400 271.8300 -104.0000 NaN
On the contrary, if you need to display the headers, I would suggest you to use the readtable function:
T = readtable("h.csv");
disp(T(1:2,:));
VarName1 VarName2 VarName3 VarName4 VarName5 VarName6 VarName7 VarName8 VarName9 VarName10 VarName11 ________ ________ ________ ________ ________ ________ ________ ________ ________ _________ _________ 51.6 -150.72 -2.0019 103.65 -70.626 -22.092 66.056 -40.393 0.16829 10.898 NaN 106.4 -295.17 -64.931 324.57 -238.19 -82.353 345.96 -384.93 255.54 -100.14 NaN
fclose(fid);
I hope this helps!

Tags

Community Treasure Hunt

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

Start Hunting!