How to use FIND function here?
2 ビュー (過去 30 日間)
古いコメントを表示
I need to find the very first corresponding value of the payload when time is 0.0000.
Next,find the corresponding value of payload when time is 1.000.Likewise when time is 2.0000 and time is 3.0000. (pls note that payload column needs to convert to decimal values) [file is attached, herewith]
below is the code i used so far:
clc
clear all
fid=fopen('test.txt');
data=textscan(fid, '%*d%f%*s%*s%*s%*d%s', 40 ...
, 'MultipleDelimsAsOne',true, 'HeaderLines',1);
fclose(fid);
S=hex2dec(data{:,7});
Any suggestions?
2 件のコメント
per isakson
2015 年 2 月 13 日
"corresponding value of payload when time is 1.000."   closest to 1 or by integration or what does "corresponding" mean?
採用された回答
per isakson
2015 年 2 月 13 日
編集済み: per isakson
2015 年 2 月 25 日
"I need to get 1st and 3rd column as my output."   Is this what you want?
fid=fopen('test.txt');
data=textscan(fid, '%*d%f%*s%*s%*s%*d%s', 40 ...
, 'MultipleDelimsAsOne',true, 'HeaderLines',1);
fclose(fid);
S = hex2dec(data{2});
my_output = cat( 2, data{1}, S );
>> whos my_output
Name Size Bytes Class Attributes
my_output 40x2 640 double
"How to use FIND function here?"   I cannot see how find could be used here.
 
Addendum with inputs from the comments
Add the following lines to the script above.
sbs = floor(my_output(:,1)) + 1;
val = accumarray( sbs, my_output(:,2), [], @mean );
t1 = accumarray( sbs, my_output(:,1), [], @min );
t2 = accumarray( sbs, my_output(:,1), [], @max );
out = [ t1, t2, val ];
fprintf( '%g, %g, %g\n', transpose( out ) )
The script will now output
0, 0.998058, 4.39375e+12
1.09832, 1.99722, 4.39375e+12
2.09746, 2.99636, 4.39375e+12
3.09557, 3.89427, 4.39375e+12
 
A second addendum with inputs from the comments
Replace
val = accumarray( sbs, my_output(:,2), [], @mean );
by
first_value = @(vec) vec(1);
val = accumarray( sbs, my_output(:,2), [], first_value );
to get "very first corresponding value of the payload".
From testing and the documentation I understand that accumarray does not keep the order of the input values.
Correction: "does not keep" should be "does keep". If not, the function, first_value would be useless.
9 件のコメント
per isakson
2015 年 2 月 21 日
In the original question you say "find the very first corresponding value". I had forgotten that when I wrote @mean. Does "real values" refer to this "first [...] value"?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!