- you can plot the line with plot
- you can find the y values for the events with interp1, and plot them with plot or scatter
- you can draw the rectangles with rectangle...but it's unclear how you want to define the size of the rectangle. For instance in your example the bottom of the green rectangle appears to be drawn using some aesthetic choice of co-ordinates. If you prefer, you can hard-code these co-ordinates (Position is x,y,width,height)
- you can do the rescaling (from 0 to 100) with rescale, it was unclear to me whether percentage was defined within the window or across the entire signal (I chose the latter below).
- you can use tiledlayout to put all three on one figure
How to plot events over a signal?
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all,
I have a signal collected over a 10 sec period (attached ‘signal’ and ‘time’ mat files).
I havetwo types of events (attached ‘a’, ‘b’, which are time points), each occurring multiple time over this 10 sec period.
1. First, I want to plot the signal and indicate over it at what time points each of these events occurred. For example, as indicated below in the figure .
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/806654/image.jpeg)
2. Then I want to indicate a window between first time event A occurs and a second time event A occurs. The same for event b as indicated in the figure below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/806659/image.jpeg)
3. Finally, I would like to plot the signal separately for each window having instead of time on x axis , percentage from 0-100%.
Could you please help?
clear
load ('Signal') % load signal
load ('Time') % load time variable
load('a'); % load event type 1
load('b'); % load event type 2
load('c'); % load event type 3
load('d'); % load event type 4
plot (time, gas_lat_env);
0 commentaires
Réponse acceptée
Dave B
le 19 Nov 2021
Here's a starting point, I think this should be enough that you can edit to get the details as you want them:
load Signal.mat
load Time.mat
load a
load b
padx=.2;
pady=.005;
tiledlayout(2,2,'TileSpacing','compact')
nexttile([1 2])
plot(time,gas_lat_env)
hold on
x1 = l_heel_strike_croppedtime;
y1 = interp1(time(~isnan(time)),gas_lat_env(~isnan(time)),x1);
plot(x1,y1,'ro','LineWidth',2)
x_bounds=[min(x1(1:2))-padx max(x1(1:2))+padx];
ind1=time>=x_bounds(1) & time<=x_bounds(2);
y_bounds=[min(gas_lat_env(ind1))-pady max(gas_lat_env(ind1))+pady];
rectangle("Position",[x_bounds(1) y_bounds(1) diff(x_bounds) diff(y_bounds)], ...
'EdgeColor','r','LineWidth',2)
x2 = l_toe_off_croppedtime;
y2 = interp1(time(~isnan(time)),gas_lat_env(~isnan(time)),x2);
plot(x2,y2,'o','LineWidth',2,'Color',[0 .6 0])
x_bounds=[min(x2(1:2))-padx max(x2(1:2))+padx];
ind2=time>=x_bounds(1) & time<=x_bounds(2);
y_bounds=[min(gas_lat_env(ind2))-pady max(gas_lat_env(ind2))+pady];
rectangle("Position",[x_bounds(1) y_bounds(1) diff(x_bounds) diff(y_bounds)], ...
'EdgeColor',[0 .6 0],'LineWidth',2)
axis padded
rs=rescale(gas_lat_env,0,100);
nexttile
plot(time(ind1),rs(ind1))
hold on
y1_rs = interp1(time(~isnan(time)),rs(~isnan(time)),x1);
plot(x1(1:2),y1_rs(1:2),'ro','LineWidth',2)
set(gca,'XColor','r','YColor','r')
axis padded
nexttile
plot(time(ind2),rs(ind2))
hold on
y2_rs = interp1(time(~isnan(time)),rs(~isnan(time)),x2);
plot(x2(1:2),y2_rs(1:2),'o','LineWidth',2,'Color',[0 .6 0])
set(gca,'XColor',[0 .6 0],'YColor',[0 .6 0])
axis padded
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spectral Measurements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!