Average based on multiple conditions
1 view (last 30 days)
Show older comments
Hi,
I have the following dataset in excel file.
In sheet 1,
Column 1= time stamp, Column 2 =velocity of car 1, Column 3= position of car 1, Column 4 = velocity of car 2, Column 5 = position of car 2, .........
In sheet 2,
Column 1 = specific time stamps, Row 1 = specific positions 1
I want to fill the table with average velocity from all cars at that specific time stamps and at that position.
Interpolation for velocity and position is acceptable.
If certain car does not have values for certain position, only the average of the available data points could be taken.
Please help me solving the problem. I really appreciate your help. Thank you.
6 Comments
Answers (1)
Walter Roberson
on 14 Mar 2020
Extract the target timestamp data and target position data from sheet2.
Extract the timestamp information from sheet1.
Determine which rows of the sheet1 timestamps correspond to the target timestamps. I will call this TR.
Extract all of the position data for rows TR. Find the minimum of it all, and subtract that from the position data.
Construct bin edges with spacing 2*3=6.
Determine which bin edges from this correspond to the target positions. I will call this TP.
Now, discretize() the position data for rows TR with the above bin edges, getting out bin numbers.
Extract the velocity data for rows TR.
For each row in TR, accumarray() passing in the bin numbers for the row in the first position, and the velocities for the row in the second position, and size [] and function @mean, and default value nan, and set the sparse flag.
From that accumarray information, extract the rows corresponding to TP, and construct an appropriate output row for it, with the current timestamp in one column, and the target positions in the remaining columns, with the information extracted from accumarray as the data for those.
Loop back for the next row in TR.
6 Comments
Walter Roberson
on 16 Mar 2020
- I am assisting multiple people, some of whom need many hours of investigation
- you have not posted any code attempts at all, so you are not invested in solving the problem, only in getting the code
- the question is obviously an assignment, so you need to be actively working on it, not expecting others to give you the code
- I already wrote a full outline of how to proceed
- volunteers have to rest too
See Also
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!