x軸を上下二軸にしたいです.上のx軸は下のx軸に対応しているようにしたいです.
Show older comments
https://jp.mathworks.com/matlabcentral/answers/379577-x-2-y-1
こちらの回答を参考に,x軸を上下二軸にしたグラフをプロットしようとしています.
figure
x1 = 0:0.1:1;
y1 = x1.^2*25/27 + x1*5/54 - 1/54;
line(x1,y1,'Color','r')
ax1 = gca;
ax1_pos = ax1.Position;
% ラベルの作成
x_Tlabel = cell2mat(cellfun(@str2num, ax1.XTickLabel, 'UniformOutput', false));
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YTick', [], 'YTickLabel', {''}, ...
'XTickLabelMode', 'manual', 'XTickMode', 'manual', ...
'XTick', x_Tlabel(2:end), 'XTickLabel',cellstr(num2str(1./x_Tlabel(2:end))), ...
'Color','none');
回答のコードを実行した場合は,上下二軸に数値が入るグラフが作成されるのですが,
x1,y1にそれぞれデータ数(1026個)の実験で得られた値を入れると,上のx軸に数値が入らない状態になってしまいます.
ax2のx軸(上のx軸)には,x1を変数として算出した結果を載せたいです.
(具体的には,データはx1が波長,y1が光強度で,ax2のx軸には周波数(波長の逆数です)をのせたいです)
宜しくお願いします.
Accepted Answer
More Answers (0)
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
