How can I split the columns of my text file as separate variables with textscan?
1 view (last 30 days)
Show older comments
I am tring to create seperate variables from each columns of my text file. My texfile is as follows:
I do not want to take headings into account so I tried to use 'commentstyle'.
Here is the code that I am using for my prevoius text files but it did not work for this one:
fileID = fopen('2500_shot1.txt');
C = textscan(fileID,'%f%f%f%f%f%f%f%f%f','delimiter',',','commentstyle','%');
fclose(fileID);
% all calib values are determined before,
% I am tring to split those columns into seperate variables.
time_shot1_2500=C{1};
shot1_2500_blast3=C{2}/calib_3;
shot1_2500_blast1=C{3}/calib_1;
shot1_2500_1C=C{4}/calib_1C;
shot1_2500_3B=C{5}/calib_3B;
shot1_2500_blast2=C{6}/calib_2;
shot1_2500_new1=C{7}/calib_new1;
shot1_2500_new4=C{8}/calib_new4;
shot1_2500_new3=C{9}/calib_new3;
However, this textscan command does not work for this text file. It executes empty cells with no values in it. Can anyone tell me what can I do else?
Thanks
1 Comment
Stephen23
on 29 Apr 2021
Note that putting meta-data (e.g. from the filename) into the variable names is likely to hinder your data processing later.
Much better would be to keep the variable names generic and store that meta-data as data in its own right.
Answers (1)
Star Strider
on 29 Apr 2021
‘I do not want to take headings into account so I tried to use 'commentstyle'.’
0 Comments
See Also
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!