Textscan issues while from file

2 次查看(过去 30 天)
vivek narayanan
vivek narayanan 2022-1-29
回答: DGM 2022-1-29
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)

回答(1 个)

DGM
DGM 2022-1-29
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).'

类别

Help CenterFile Exchange 中查找有关 Standard File Formats 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by