2017-01-14 9 views
0

Matlab(バージョンR2014b)で散布図の行列を作成し、各x軸とy軸に対して2つのティック(最小値と最大値)を使用したいので、実際の例にはより多くのプロットがあり、読みやすくなります。ここに例があります。ご覧のように、2番目のforループはティックを編集するようには機能していません。また、forループなしでこれを設定する方法はありますか?複数のXTick値を一度に変更する

% Example data 
     example = [ -5.2844 5.0328 307.5500 
    -12.0310 5.1611 237.9000 
    -15.9510 7.5500 290.7600 
    -11.5500 13.6850 285.8400 
    -1.9356 9.4700 273.2600 
    -9.2622 4.7456 232.6000 
    -6.5639 5.2272 265.3800 
    -4.4795 14.8320 281.1300 
    -2.1474 13.0690 288.7300 
    -3.7342 11.7450 265.2200 
    -11.9040 10.9660 286.5700 
    -2.1789 6.7442 258.9700 
    -2.8316 11.8210 281.7500 
    -2.6170 7.4740 244.8600 
    -6.8770 1.6623 116.9800 
    -10.2210 5.7575 300.2200 
    -3.9430 5.9715 253.6000 
    -3.3690 5.6530 230.9700 
    2.6090 3.2750 236.8700 
    -5.1430 8.4060 273.9600 
    -7.9360 2.7855 254.8200 
    -2.8665 2.0241 176.0600 
    -0.0960 3.3165 228.6800 
    -8.8465 10.3240 289.2100 
    -8.1930 16.4070 289.7000 
    -6.5840 13.4010 283.2600 
    2.2405 8.4625 270.1000 
    -2.2505 7.5555 285.9100 
    -4.6955 6.2985 279.2000 
    -0.7610 12.5210 283.2000 
    -0.7510 9.9470 279.9100 
    1.7120 8.5990 285.5700 
    -0.6245 7.6905 251.9100 
    -19.2320 6.8545 306.2700 
    -4.1255 9.8265 298.2000 
    2.9486 3.8881 250.2100 
    1.7333 5.5000 240.7300 
    -6.5881 3.9152 234.3800 
    -7.9543 8.0771 276.8000 
    -6.9641 8.8573 284.2800 
    -10.3280 7.4768 291.8700 
    -8.0818 5.1250 250.6600 
    -10.1490 3.9427 271.0000 
    -2.7786 3.7673 213.6500 
    -14.5410 11.1500 288.9100 
    -6.8118 11.0210 280.2000 
    -2.6459 6.5127 213.2600 
    1.4036 4.2023 253.9400 
    -5.0014 9.3900 267.0600 
    -9.7382 12.0990 290.8800] 

% Labels for data 
data_labels = {'Variable1','Variable2',... 
    'Variable3'}; 

% Make scatterplot matrix with histogram on diagonal 
figure() 
[H,AX]= plotmatrix(example(:,:)); 

% label the axes of the plots (rotated) works fine 
for i = 1:length(AX) 
    ylabel(AX(i,1),data_labels{i},'Rotation',0,'HorizontalAlignment','right',... 
     'FontSize',12); 
    xlabel(AX(end,i),data_labels{i},'Rotation',60,'HorizontalAlignment','right',... 
     'FontSize',12); 
end 

% Set ticks (not working yet) 
NumTicks = 2; 
for i = 1:length(AX) 
    L = get(AX(i,i),'XLim'); 
    set(AX(i,i),'XTick',linspace(L(1),L(2),NumTicks)); 
    % set y ticks here too 
end 
+0

最後のループで 'AX(i、i)'の代わりに 'AX(i)'を使う必要があります – Suever

答えて

1

AXにインデックスを付けるとき、あなたは間違ってi両方添字を使用しています。

AX(i) % Rather than AX(i,i) 

はまた、lengthよりもnumelを使用して(つまり、ビルトイン0 + 1iのためにMATLABだから)、変数ではなく、あなたのループ変数としてiを使用することをお勧めします。また、行と列の添字を指定するのではなく、1つの線形インデックスをAXに使用することもできます。あなたがループwitnoutこれをしたい場合は

for k = 1:numel(AX) 
    L = get(AX(k),'XLim'); 
    set(AX(k),'XTick',linspace(L(1),L(2),NumTicks)); 
end 

、あなたは技術的にそれが

set(array_of_plot_handles, {'Property'}, array_of_values_to_set) 

だから、次の構文を使用してオブジェクトcellfun、あなたが複数のプロットで同じプロパティを設定することができるという事実を利用して行うことができますあなたの問題に適用され、それが

% Get all XLims as a cell array 
oldlims = get(AX, 'XLim'); 

% Compute the new xlims 
newlims = cellfun(@(x)linspace(x(1), x(2), NumTicks), oldlims, 'UniformOutput', false); 

% Now set the values 
set(AX, {'XTick'}, newlims); 

ようなものになるだろうそれとも、実際にそれが1行になりたい場合は

set(AX, {'XTick'}, cellfun(@(x)linspace(x(1),x(2),NumTicks), get(AX, 'Xlim'), 'UniformOutput', false)) 
+0

cellfunは美しく動作します!元の 'for'ループを編集しても、まだ正しくはありません。おそらくget(AX(i、i)...)は更新が必要です。 – user2860703

+0

@ user2860703 updated。 – Suever

+0

大きな包括的な例+1 – user2860703

関連する問題