Combine two MATLAB figures with two different y axes

조회 수: 6 (최근 30일)
Belinda
Belinda 2023년 11월 16일
댓글: Sulaymon Eshkabilov 2023년 11월 17일
Hi, I have such a similar problem, like describes in the followink, link but using this code https://de.mathworks.com/matlabcentral/answers/525423-combine-two-matlab-figures-with-two-y-axes
results in such too small range of visualized data of the file "VR Acc x".
x-axis of the figures do not matter, they represent same timeline
Can anybody please help me that the range can be set to a nice display of this small data range of the y-axis?
That acceleration data an gyroskopic data iare shown within their plausible ranges?
  댓글 수: 2
Les Beckham
Les Beckham 2023년 11월 16일
The figures that you attached are not showing the two sets of data on the same plot (with two y axes) as you seem to want, based on the link you show.
Can you show the code you have written to make the desired plot, and the result? Also, what is it that you don't like about the result?
Belinda
Belinda 2023년 11월 17일
Sorry I don't have access to the code, only the given figures :(

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

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 11월 16일
Is this what you want to obtain:
fig1 = openfig('qualitatixe Analyse VR ACCx_31_35sek.fig');
fig2 = openfig('qualitatixe Analyse VR gyr z_31_35sek.fig');
ax1 = findobj(fig1, 'type', 'axes');
yyaxis(ax1, 'left');
line1L = ax1.Children;
ax2 = findobj(fig2, 'type', 'axes');
yyaxis(ax2, 'left');
line1R = ax2.Children;
fig = figure;
ax = axes();
yyaxis(ax, 'left');
LineL = copyobj(line1L, ax);
ylabel('G [9,81m/s²] ')
yyaxis(ax, 'right');
LineR = copyobj(line1R, ax);
ylabel('Winkeländerung [dps]')
yyaxis(ax, 'left');
ax.YLim = [-4.65 4.65]; % change Ylimits of left axes if necessary
yyaxis(ax, 'right');
ax.YLim = [-225 225]; % change Ylimits of right axes if necessary
xlim([0, 120]) % change Xlimits if necessary
legend('G ', 'Winkeländerung', 'Location', 'Best')
grid on
  댓글 수: 3
Belinda
Belinda 2023년 11월 17일
thank you for your help!I spend so many hours with trying to fix my problem and this code runs so easy !
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 11월 17일
Most welcome! Glad to be of some help :)

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

추가 답변 (1개)

William Rose
William Rose 2023년 11월 16일
I packaged the raw data into a single .mat file, attached. I will make two figures. Figure 1 has two panels. Figure 2 has right and left y-axes.
load('Belinda');
figure
subplot(211); plot(x1,y1,'-r'); xlim([86 90]); grid on
subplot(212); plot(x2,y2,'-g'); xlim([86 90]); grid on
figure
yyaxis left; plot(x1,y1,'-r');
xlim([86 90]); ylim([-5 5]); grid on
set(gca, 'YColor','r')
yyaxis right; plot(x2,y2,'-g');
xlim([86 90]); ylim([-250 250])
set(gca, 'YColor','g')
Good luck.
  댓글 수: 2
Belinda
Belinda 2023년 11월 17일
thank you, this code works great!
William Rose
William Rose 2023년 11월 17일
@Belinda, you are welcome.

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by