Hello
I have read my data from an excel file(attached here) and ploted them on a loglog scale,now I want to show another xaxis on the top of my figure (except my current x axis at the bottom) with just different scale . I tried the code inside the %%—%% but it did not work.The code outside of this part goes well.
could you please give me some idea how to add a second x axis to my figure.
I appreciate your time in responding to whatever you can.
thank you
clear allclcnumdata = xlsread('test.xls');Mw = numdata(:,1);Area = numdata(:,2);moment=10.^( 1.5.*Mw + 9.1 )figure(1)loglog(moment,Area,'ko',... 'MarkerEdgeColor','w',... 'MarkerFaceColor','k',... 'MarkerSize',6)%% ---------
% part to add x axis on top
ax1 = gca; % current axes
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position', ax1_pos,'Color', 'none')set(ax2, 'XAxisLocation', 'top')% % set the same Limits and Ticks on ax2 as on ax1;
set(ax2, 'XLim', get(ax1, 'XLim'))set(ax2, 'XTick', get(ax1, 'XTick'))nticks = 6;tickpos=[7 7.5 8 8.5 9 9.5]set(gca, 'XTick', tickpos) set(ax2,'Ytick',[]);%%----------
c=1.77e-10;M0=moment;yCalc2=(c.*moment.^(2/3))hold onloglog(moment,yCalc2,'c-','LineWidth',1)sim_moment = numdata((1:9),3);sim_Area = numdata((1:9),4);loglog(sim_moment,sim_Area,'mh',... 'MarkerEdgeColor','w',... 'MarkerFaceColor','m',... 'MarkerSize',9)xlabel('Moment (Nm)')ylabel('Rupture Area (km^{2}) ')saveas(gcf,'test.png')
Best Answer