Extracting a particular data from the original data

I have a data file named rd.txt attached below. 1st column data refers to time and all other columns refers the corresponding distance. Now I want to extract the data for 0.02,0.04,0.06,...60.00 sec (at a difference of 0.02) from 1st column and corresponding distances. Is there a way to extract data from the original data for a particular values? Your answer is highly appreciated. Thank you.

 採用された回答

Star Strider
Star Strider 2016 年 11 月 14 日

1 投票

You may not be reading your data correctly.
This works for me without error:
fidi = fopen('sam moor rd.txt','rt');
Dcell = textscan(fidi, repmat('%f',1,9), 'CollectOutput',1, 'Delimiter',' ');
D = cell2mat(Dcell);
L = size(D,1);
t = D(:,1);
q = length(t > 0)/L;
ti = 0 : 0.02 : max(t); % Interpolation Vector
Di = interp1(t, D(:,2:end), ti, 'linear'); % Interpolated Data

2 件のコメント

sam moor
sam moor 2016 年 11 月 14 日
i am getting time 0,0,0...0 it should be 0.02,0.04....60 You can used this original roof-disp.out file. Its same file as rd.txt
Star Strider
Star Strider 2016 年 11 月 14 日
編集済み: Star Strider 2016 年 11 月 14 日
I eliminated the first column from the ‘Di’ matrix, because that is the time vector to use for the interpolation.
Adding the ‘rd_new’ assignment will give you the complete, interpolated ‘rd’ matrix:
fidi = fopen('sam moor rd.txt','rt');
Dcell = textscan(fidi, repmat('%f',1,9), 'CollectOutput',1, 'Delimiter',' ');
D = cell2mat(Dcell);
L = size(D,1);
t = D(:,1);
ti = 0.02 : 0.02 : max(t); % Interpolation Vector
Di = interp1(t, D(:,2:end), ti, 'linear'); % Interpolated Data
rd_new = [ti' Di]; % Complete Interpolated ‘rd’ Matrix
EDIT Corrected to begin ‘ti’ at 0.02 rather than 0.00.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 11 月 14 日

0 投票

I suggest you read the the FAQ on comparing floating point numbers and then use that or try a new function called ismembertol() to find out which rows match your desired times. One might think intersect() might work but because of the FAQ I referred you to, I have my doubts.

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

質問済み:

2016 年 11 月 14 日

編集済み:

2016 年 11 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by