How can I divide my text file in several blocks?

2 次查看(过去 30 天)
I want to read my text file "January_5d" and divide it in 5 different blocks(day by day)because I would like to plot the several trending. What I have so far is:
% code
YourFilePath = 'C:\Users\Matlab\January_5d.txt';
fid = fopen(YourFilePath ,'rt');
Datafile = textscan(fid,'%s%s%s%s%s','Headerlines',2);
%Allocate all the measured value in the "Value1" variable
Value = Datafile{3};
Value = cellfun(@(x) textscan(x,'%s','Delimiter', ' ')',Value ,'UniformOutput',false);
Y = vertcat(Value{:});
X = cellfun(@transpose,Y,'UniformOutput',false);
Z = cellfun(@str2double,X,'UniformOutput',false);
Value1=cell2mat(Z);
%Allocate all the times in the "Time1" variable
Time (:,1)= Datafile{2};
Time1=cell2mat(Time);
%close the text file
fclose(fid);
With this code I can read all the file and store all the data in the 2 variables 'Value1' and 'Time1' but I don't know how I could store the data in 5 different blocks(day by day).Can someone help me?

采纳的回答

per isakson
per isakson 2014-5-13
编辑:per isakson 2014-5-13
This function outputs a diagram for day one
function cssm
YourFilePath = 'h:\m\cssm\January_5d.txt';
fid = fopen( YourFilePath, 'rt' );
Datafile = textscan( fid, '%s%s%f%s%s' ...
, 'Headerlines',2, 'CollectOutput', true );
fclose(fid);
%Allocate all the measured value in the "Value1" variable
Value1 = Datafile{2};
%Allocate all the times in the "Time1" variable
Time1 = datevec( cell2mat( Datafile{1} ), 'yyyy-mm-ddHH:MM:SS' );
block1 = Value1( Time1(:,3)==1 );
t1 = Time1 ( Time1(:,3)==1, : );
figure, plot( datenum(t1)-datenum(t1(1)), block1 )
end
  3 个评论
per isakson
per isakson 2014-5-13
编辑:per isakson 2014-5-13
On CollectOutput doc says
If true, then textscan concatenates consecutive output cells of
the same fundamental MATLAB class into a single array.
I think that data and time concatenated makes the code easier to read and understand. Yes, this just one way out of several alternatives.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by