How do I target values within a range for different variables within the same given time series?

6 次查看(过去 30 天)
For example I have 4 variables withing a timeseries that records data at 10 hz for an interval of 600 seconds. This results in 4 arrays (1x6000). Say the variables are Speed, Distance, Elevation, and Air Temperature. I want to catagorize these variables based on elevation. Say I want to know the speed, distance, and air temperatures based on every 100ft I travel in elevation. Say 100ft, 200ft, 300ft, etc. all the way up to 1000ft. I won't travel the same distance or move at the same speed for each elevation level, so this would result in different sized arrays for each 100ft of elevation. I have been successfully targeting one variable at a time, but I am having trouble creating a loop that would obtain the information to catagorize the data togehter at each elevation level.
segments.sample.start = 0;
segments.sample.stop = 6000;
segments.freq=.1;%seconds per sample
time = (segments.sample.start:segments.sample.stop)*segments.freq;
p10 = find(elevation>=1000);
p9 = find(elevation>=900 elevation<100);
p8 = find(elevation>=800 & elevation<900);
p7 = find(elevation>=700 & elevation<800);
p6 = find(elevation>=600 & elevation<700);
p5 = find(elevation>=500 & elevation<600);
p4 = find(elevation>=400 & elevation<500);
p3 = find(elevation>=300 & elevation<400);
p2 = find(elevation>=200 & elevation<300);
p1 = find(elevation>=100 & elevation<200);

回答(1 个)

Star Strider
Star Strider 2024-1-11
I do not completely understand what the data are, or the lengths or content of the various data arrays.
It might be worthwhile to consider interpolating the various values, exspecially if they have a specific set of variables in common (for example the time of the observation, although I cannot determine if time is recorded for each observation from the information provided). Using the interp1 function for example could provide a common set of interpolated values (as a matrix) that could then be used for more general interpolations. Other interpolation funcitons could be appropriate, such as scatteredInterpolant or interpn.
It would help to have the data, or a representative sample of it, as well as a descirption of a typical task.
  2 个评论
Kendell
Kendell 2024-1-11
I am running an experiment essentially, these variables are just made up as an example. The data has already been recorded and outputted to the variable list in matlab. Sorry if that short bit I wrote wasn't enough to understand.
Let's try this again, a smaller scale would be easier. Lets say that I am hiking and I want to study the effects of elevation and how it affects my hike. The hiking won't be gradual for this example, the levels will be 100 ft, 200ft, 300ft, 400ft, 500ft, 600ft, 700ft, 800ft, 900ft, 1000ft. So consider I spend x amount of time at 100ft then take a ladder up to the next level and start the 200ft level, then so on:
I have 3 variables:
Time (all of the data was recorded with respect to a timeseries)
Speed (at which I am moving)
Elevation (height of the path I am hiking)
Say it takes me 1 hour or 3600s to complete the experiment. I would like to find out where within that array of time that I am hiking 300ft above sealevel. Once I find out where in the array of the timeseries that it lies, I would like to recall the values of my variable (Speed) that matches the time I was at 300ft.
If data is recorded in 1 Hz, the total experiment would be a time array of (1x3600). Say I spent 360s hiking 300ft above sea level, but I didn't start hiking at the 300ft mark until 6 mins (720s) into the experiment. Therefore within the time array, the time spent hiking at 300ft would be time3 = 720:1080 (out of the 1:3600 time of the experiment) resulting in an array for the variables at a size of (1x360).
I am struggling to use loops to bin the data at each elevation.
Variables.Time = (1:3600); %s
Variables.Speed = randi([1 10],1,3600); %mph
E1 = ones(1,360)*100;
E2 = ones(1,360)*200;
E3 = ones(1,360)*300;
E4 = ones(1,360)*400;
E5 = ones(1,360)*500;
E6 = ones(1,360)*600;
E7 = ones(1,360)*700;
E8 = ones(1,360)*800;
E9 = ones(1,360)*900;
E10 = ones(1,360)*1000;
Variables.Elevation = [E1 E2 E3 E4 E5 E6 E7 E8 E9 E10]; %ft
p10 = find(Variables.Elevation==1000);
p9 = find(Variables.Elevation==900);
p8 = find(Variables.Elevation==800);
p7 = find(Variables.Elevation==700);
p6 = find(Variables.Elevation==600);
p5 = find(Variables.Elevation==500);
p4 = find(Variables.Elevation==400);
p3 = find(Variables.Elevation==300);
p2 = find(Variables.Elevation==200);
p1 = find(Variables.Elevation==100);
% Need to figure out how to loop to find speeds when at x elevation
for k = p10
speed10(k) = Variables.Speed(k);
end
Star Strider
Star Strider 2024-1-11
编辑:Star Strider 2024-1-12
I am stil not certain what your data are or what you are doing.
There are MATLAB functions that make the data binning much easier, one of which is accumarray. There are others such as findgroups, groupsummary, and splitapply that would also work. I have more experience with accumarray, so I use it here.
Example —
time = datetime(2024,1,11) + seconds(0:3599).'; % Time Vector (1 Hz Samplinmg Frequency)
elev = sort(randi([100 1000],size(time))); % Elevations (Rounded To Hundreds)
% [e1,e2] = bounds(elev)
Data = table(time,elev) % Hypothetical Data
Data = 3600×2 table
time elev ____________________ ____ 11-Jan-2024 00:00:00 100 11-Jan-2024 00:00:01 100 11-Jan-2024 00:00:02 100 11-Jan-2024 00:00:03 100 11-Jan-2024 00:00:04 100 11-Jan-2024 00:00:05 101 11-Jan-2024 00:00:06 101 11-Jan-2024 00:00:07 101 11-Jan-2024 00:00:08 102 11-Jan-2024 00:00:09 102 11-Jan-2024 00:00:10 102 11-Jan-2024 00:00:11 102 11-Jan-2024 00:00:12 102 11-Jan-2024 00:00:13 102 11-Jan-2024 00:00:14 103 11-Jan-2024 00:00:15 103
figure
stairs(Data.time, Data.elev)
grid
xlabel('Time')
ylabel('Elevation')
elev_d = round(Data.elev/100)*100;
[U_elev,~,eix] = unique(elev_d, 'stable');
elev_time = accumarray(eix, (1:numel(eix)).', [], @(x) max(minute(Data.time(x)))-min(minute(Data.time(x))) );
Result = table(U_elev, elev_time)
Result = 10×2 table
U_elev elev_time ______ _________ 100 3 200 7 300 6 400 7 500 7 600 7 700 7 800 6 900 6 1000 3
Real data might have more complicationos and so be more difficult to deal with. This is simply an illustration of how I might go about analysing it.
EDIT — (12 Jan 2024 at 02:35)
Added second example with some variation in the elevation profile.
time = datetime(2024,1,11) + seconds(0:3599).'; % Time Vector (1 Hz Samplinmg Frequency)
elev = sort(randi([100 1000],size(time))); % Elevations (Rounded To Hundreds)
% [e1,e2] = bounds(elev)
Data = table(time,elev); % Hypothetical Data
Data.elev = Data.elev + 28*sin(2*pi*(0:3599)/810).'
Data = 3600×2 table
time elev ____________________ ______ 11-Jan-2024 00:00:00 100 11-Jan-2024 00:00:01 100.22 11-Jan-2024 00:00:02 100.43 11-Jan-2024 00:00:03 100.65 11-Jan-2024 00:00:04 100.87 11-Jan-2024 00:00:05 101.09 11-Jan-2024 00:00:06 101.3 11-Jan-2024 00:00:07 101.52 11-Jan-2024 00:00:08 102.74 11-Jan-2024 00:00:09 103.95 11-Jan-2024 00:00:10 105.17 11-Jan-2024 00:00:11 105.39 11-Jan-2024 00:00:12 106.6 11-Jan-2024 00:00:13 106.82 11-Jan-2024 00:00:14 107.03 11-Jan-2024 00:00:15 108.25
figure
stairs(Data.time, Data.elev)
grid
xlabel('Time')
ylabel('Elevation')
elev_d = round(Data.elev/100)*100;
[U_elev,~,eix] = unique(elev_d, 'stable');
elev_time = accumarray(eix, (1:numel(eix)).', [], @(x) max(minute(Data.time(x)))-min(minute(Data.time(x))) );
Result = table(U_elev, elev_time)
Result = 10×2 table
U_elev elev_time ______ _________ 100 1 200 10 300 4 400 9 500 4 600 9 700 4 800 10 900 4 1000 4
.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by