Textscan issues while from file

2 views (last 30 days)
vivek narayanan
vivek narayanan on 29 Jan 2022
Answered: DGM on 29 Jan 2022
Hi,
I have some issues with textscan function.
fid = fopen('winadcp.txt','r') ;
data = textscan(fid,'%d %d','Delimiter',' ','HeaderLines',16)
D=cell2mat(data);
fclose(fid);
When i run the code(eg), the values stored in D is across the coloumn(attached)

Answers (1)

DGM
DGM on 29 Jan 2022
I have no idea what this data is, but I'm going to guess that reading every other value into two vectors makes no sense. Since I don't know what it is, I'm just going to read it into a single vector. There appear to be seven samples and then a timestamp for an 8th sample, but no corresponding data. I discard the dangling timestamp because I assume it's of no use. The rest I just reshape into a 7x117 matrix, one row per sample. If you know what everything is in each sample, you can further split the rows into their relevant blocks.
fid = fopen('test.txt','r') ;
data = textscan(fid,'%d','Delimiter',' ','HeaderLines',16);
D = cell2mat(data);
fclose(fid);
% define the size of each sample
blocksize = 117;
% truncate and reshape
nblocks = floor(numel(D)/blocksize);
D = reshape(D(1:nblocks*blocksize),blocksize,nblocks).'

Categories

Find more on Data Import and Export in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!