Hello again
Does anybody know how i can plot a graph that looks like this or point me in the direction of a good tutorial that will help me figure it out? I have 8 sensor readings for a number of different movements and I want to display each sensors readings on a single figure like this opposed to using subplots, is this possible?
Thanks in advance

 채택된 답변

Star Strider
Star Strider 2019년 4월 8일

0 개 추천

Use the bsxfun function to add an offset value to each row of a matrix of signals.
Example —
t = linspace(0, 36, 250); % Create Data
y = sin([1:6]'*t*2*pi); % Create Data
yofst = bsxfun(@plus, y, (1:size(y,1))'*2); % Add Constant Offset Values To Each Row
figure
plot(t, yofst)
grid
After that, you can do whatever you like with the tick values and labels. See the documentation for Axes Properties (link) and related functions.
Experiment to get the result you want.

댓글 수: 4

CHRISTOPHER MILLAR
CHRISTOPHER MILLAR 2019년 4월 8일
편집: CHRISTOPHER MILLAR 2019년 4월 8일
Is there any documentation that explains what you have shown me in the above example?
What documentation do you want?
The documentation for bsxfun (binary singleton expansion function) describes how it works. Here that means adding a constant (an element of the ‘(1:size(y,1))'*2’ column vector, essentially [2; 4; 6; 8; 10; 12]) to each row of ‘y’.
The essence of my code is simply:
y(1,:) + 2;
y(2,:) + 4;
. . .
y(6,:) + 12;
The bsxfun function makes this more efficient.
The argument of the sin function is simple vector multiplication of the column vector and a row vector to produce a matrix, and is described in any text on linear algebra. It simply exists to provide a matrix of signals for bsxfun to work with in order to demonstrate the code, and is not otherwise necessary. You can use any vector in place of ‘t’, and any matrix in place of ‘y’, providing the matrix is 2D and they have at least one dimension in common.
I have only been working with Matlab for a week or 2 so I am still tying to get to grips with it.
Thanks for your help, I was able to use your solution to produce the figure exactly as I needed it to.
As always, my pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bob Thompson
Bob Thompson 2019년 4월 8일

0 개 추천

I you are looking for separate plots like that I would suggest using subplot. This will allow you to present multiple plots in one figure.
Alternatively, you can also plot multiple sets of data into one plot by entering 'hold on' somewhere before the second set of data is plotted (must be activated for each figure, if multiple figures are being created). I believe newer versions of Matlab automatically change the color of the lines for each data set, but it is also possible to do this manually.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

릴리스

R2018b

태그

Community Treasure Hunt

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

Start Hunting!

Translated by