MATLAB Answers

creating graph with multiple axis

23 views (last 30 days)
Satyam Singh
Satyam Singh on 22 Jul 2020 at 10:17
Commented: Sugar Daddy on 22 Jul 2020 at 10:57
I am trying to create a graph with 2 x axis and 2 y axis. I got a code which is working fine but there is an issue. it is not able to relate both the x axis.
So this the graph I am getting using the code below and the excel sheet attached here-
x1 = cell2mat (Nickel(:,3));
y1 = cell2mat(Nickel(:,1));
line(x1,y1,'Color','r')
ax1 = gca; % current axess
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
x2 = cell2mat(Nickel(:,4));
y2 = cell2mat(Nickel(:,2));
line(x2,y2,'Parent',ax2,'Color','b')
the problem that I am having is both the x axis are not related which means the red curve should be formed according to x1,x2 and y1. If you see the image below for reference just look at the peak number 6 of blue colored curve it is coming after 20 in fractions but in above graph it is before 20. So this the problem that I am not able to figure out. Please help me.

  1 Comment

Sugar Daddy
Sugar Daddy on 22 Jul 2020 at 10:57
maybe because it is semilogx

Sign in to comment.

Answers (0)