Textscan issues while from file

2 visualizzazioni (ultimi 30 giorni)
vivek narayanan
vivek narayanan il 29 Gen 2022
Risposto: DGM il 29 Gen 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)

Risposte (1)

DGM
DGM il 29 Gen 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).'

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by