Eliminating Certain Timestamps from an Array

7 ビュー (過去 30 日間)
Midimistro
Midimistro 2016 年 5 月 23 日
コメント済み: Sean de Wolski 2016 年 5 月 24 日
I have two arrays: "Time" and "Bytes", both of which correspond to one another (aka, are the same size and refer to the same type of data). I need to eliminate certain data points in "Time" containing duplicate timestamps, but at the same time, select those with the higher "Byte" value for that timestamp.
For starters, I know I can use unique() to find the non-duplicate timestamps, but this function doesn't take into consideration finding the max value of Bytes in the process. Is there any simple way of going about this?
Whether the answer is in function form or in-line form doesn't matter to me. If you need an example of data, let me know.

採用された回答

Sean de Wolski
Sean de Wolski 2016 年 5 月 23 日
編集済み: Sean de Wolski 2016 年 5 月 24 日
NEW
x = [.01, .01, .03, .04, .04, .04, .07, 1.0] ;%Timestamp
y = [096, 140, 096, 096, 140, 579, 579, 579] ;%Bytes
z = [.01, .02, .03, .04, .04, .06, .09, 1.2]; %TimestampEnd
[ux,~,idx] = unique(x');
zmx = accumarray(idx,(1:numel(x))',[],@(ii)getz(y(ii),z(ii)));
[ux zmx]
Where getz() is in getz.m.
function mxz = getz(y,z)
[~, idxmx] = max(y);
mxz = z(idxmx);
end
OLD
x = [1;2;3;2;3]; % "time stamps"
y = (1:5)'; % Bytes, pick max for each unique x.
[ux,~,idx] = unique(x);
xmx = accumarray(idx,y,[],@max);
[ux xmx]
Use the third output of unique to pivot and apply the max function with accumarray.
  3 件のコメント
Midimistro
Midimistro 2016 年 5 月 23 日
I also forgot that there's a third datapoint I forgot to mention that needs to have the same indecies as the new timestamp.
The data is more like this:
x = [.01, .01, .03, .04, .04, .04, .07, 1.0] %Timestamp
y = [096, 140, 096, 096, 140, 579, 579, 579] %Bytes
z = [.01, .02, .03, .04, .04, .06, .09, 1.2] %TimestampEnd
And the results should look something like this:
xnew = [.01, .03, .04, .07, 1.0]
znew = [.02, .03, .06, .09, 1.2]
These new data points are then used within a function to find whether these data points match another set of data points, but that's a separate problem.
Sean de Wolski
Sean de Wolski 2016 年 5 月 24 日
See NEW above.
You need to back index from the max of y into the corresponding z. It's nice to do this in a separate function.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by