Hi,
I want to plot arrival pulsed signals in a time sequence similar to the attached figure.
Basically, I have to flip the signals 90 degree and number each signal corresponding to its offset. I think it is going to be a multi y-axis plot. How to plot multiple graphs with multiple y-axes which share the same x-axis?
Thank you

 Accepted Answer

Plot ias you normally would, using the fill function, then rotate it using the view function:
offset = 1:2:20; % Create Data
time = linspace(0, 1, 250); % Create Data
frq = 1:10; % Create Data
signal = bsxfun(@plus, sin(frq(:)*time*3*pi), offset(:)); % Create Data
figure
fill(time, signal, 'g')
view(90, 90)
xlabel('Time (s)')
ylabel('Offset (km)')
Experiment to get the result you want.

2 Comments

This looks nice! However, what does the function bsxfun actually do? I understand that it is used to stack up all plots together
Thank you!
The bsxfun function performs the desired operation specified in the first argument by expanding the single dimension the two arguments share (here 10) and then doing the operation (here, addition). I think of ‘bsx’ as standing for ‘binary singleton expansion’.
The alternative is to use a for loop to perform the addition, or using the repmat function to create a matrix of ‘offset’ values equivalent to the size of the original signal matrix (created here by the sin call), and then adding. The bsxfun function is significantly faster and more efficient than either of these, even for small problems.
In my code, bsxfun adds the ‘offset’ vector to the matrix created by the sin call ‘sin(frq(:)*time*3*pi)’ to separate the rows by increments of 2 to keep them from overlapping. You can choose larger (and non-integer) increments for ‘offset’ if you want, so long as the length of the vector is the same as the row size (dimension 1) of your original matrix of signals (in my code, created by the sin call, in your code, your data matrix of signals).
Without the bsxfun call, the signals would plot on top of each other, all centred at y=0 rather than separated vertically (or after the view call, horizontally).

Sign in to comment.

More Answers (0)

Categories

Find more on Measurements and Spatial Audio in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!