How can I divide my text file in several blocks?

2 ビュー (過去 30 日間)
Matteo
Matteo 2014 年 5 月 13 日
コメント済み: Matteo 2014 年 5 月 13 日
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.
Matteo
Matteo 2014 年 5 月 13 日
You are right!thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by