フィルターのクリア

Could someone please show me how to add time data?

1 回表示 (過去 30 日間)
Tony Pate
Tony Pate 2016 年 7 月 26 日
編集済み: per isakson 2016 年 7 月 27 日
I have eleven files that each have a column with time data. They all start at zero seconds, but are not all exactly the same in length. I would like to put these files into one large file with the time in sequence starting with zero and becoming larger with each file, not starting back at zero after each file. What is an efficient way of doing this? I have tried a few things but nothing will work for files with irregular lengths. Any help would be greatly appreciated.
  8 件のコメント
Tony Pate
Tony Pate 2016 年 7 月 26 日
How can I fix my code knowing that there is a slight difference with the time-step? How can I read in the last time value for each file to put them all together?
dpb
dpb 2016 年 7 月 27 日
That dT is fixed (not 0.002, but constant) within machine roundoff. If that's so for each file, then I'd revert to the previous technique just using the actual difference instead of the approximate 0.002; how can it possibly matter if you're concatenating files that didn't come sequentially in the first place?

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

採用された回答

per isakson
per isakson 2016 年 7 月 26 日
編集済み: per isakson 2016 年 7 月 26 日
Here is one way of doing it. I use four copies of you example file for this test.
tic
folderspec = 'h:\m\cssm';
glob = 'Example_DROID*.mat';
X = cssm( folderspec, glob );
toc
dX = diff(X(:,1));
disp( [ max(dX), min(dX)] )
outputs
Elapsed time is 0.109893 seconds.
0.001953000000000 0.001952999999997
>>
where
function X = cssm( folderspec, glob )
sad = dir( fullfile( folderspec, glob ) );
len = length( sad );
cac = cell( 1, len );
dt = 0.001953; % magic number
dX1 = 0;
for jj = 1 : len
S = load( fullfile( folderspec, sad(jj).name ) );
S.X(:,1) = S.X(:,1) + dX1;
cac{jj} = S.X;
dX1 = S.X( end, 1 ) + dt;
end
X = cat( 1, cac{:} );
end
  5 件のコメント
per isakson
per isakson 2016 年 7 月 27 日
編集済み: per isakson 2016 年 7 月 27 日
  • folderspec is a variable name, which I use for the full name of a directory path. In Matlab the name, path, is taken.
  • glob is a variable name, which is often used for filenames with wildcard characters. See glob (programming)
per isakson
per isakson 2016 年 7 月 27 日
編集済み: per isakson 2016 年 7 月 27 日
"to get a consistent dt of the entire group of files" &nbsp Why do you want that?
"if the dt changes a good bit from file to file?" &nbsp If so, it's for some reason.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by