set axes limit manual
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello.
I have used interpo2 funtion.
I had a matrix of 11x11 and now I have a matrix of 20x20.
I plot and the axes limit goes from 0 to 20. However the original value of X goes from 0 to 11.
How can I fix the value of the axes from o to 11?
Thank you in advance.
Regards,
María
댓글 수: 0
답변 (3개)
Cris LaPierre
2021년 9월 18일
Can you share your code? It sounds like you are not providing an x input to your plot command. If not, MATLAB is using the index of the number in the vector as the X value. The simplest fix is to specify X and Y coordinates in your plot command.
X = 0.5:.5:10;
Y = 1:20;
% plot(y)
plot(Y)
% plot(x,y)
hold on
plot(X,Y)
hold off
legend(["Just Y","(X,Y)"])
댓글 수: 0
Cris LaPierre
2021년 9월 18일
Ah, you actually meant 11x11 and 20x20. I had figured that was just a typo based on the question. imagesc is going to use row number for Y and column number for X by default. Use the following syntax to specify different values.
This seems to put the axes back into XY mode, meaning (0,0) is the bottom left corner. In images, (0,0) is the top left corner. Here's what the final solution might look like.
A= [ 0 0 0.149 0.524 0.717 0.268 0.275 0.340 0.330 0.943 0.623;
0 0 0.402 5.518 9.337 4.833 1.370 2.233 2.675 6.665 6.960;
0 0 0 0.710 6.047 6.910 1.925 1.117 1.186 3.558 7.161;
0 0 0 0 1.040 3.759 3.451 0.662 0.558 1.352 3.471;
0 0 0 0 0.042 0.985 2.449 0.700 0.325 0.618 1.732;
0 0 0 0 0 0.146 0.978 0.787 0.166 0.380 1.059;
0 0 0 0 0 0.015 0.179 0.427 0.164 0.228 0.516;
0 0 0 0 0 0 0.007 0.127 0.084 0.094 0.233;
0 0 0 0 0 0 0 0.032 0.052 0.084 0.089;
0 0 0 0 0 0 0 0.017 0.032 0.030 0.055;
0 0 0 0 0 0 0 0 0.007 0.040 0.052];
newNumberOfRows = 30; % set the number of rows interpolated rows you want
newNumberOfCols = 30; % set the number of columns interpolated rows you want
[x, y] = meshgrid(1:size(A,2), 1:size(A,1));
[xq, yq] = meshgrid(linspace(1, size(A, 2), newNumberOfCols), linspace(1, size(A, 1), newNumberOfRows));
newMatrix = interp2(x, y, A, xq, yq);
B=newMatrix;
% Show image with original X,Y limits.
imagesc('XData',[1 size(A,2)],'YData',[1 size(A,1)],'CData',B)
% Orient and scale the axes
axis ij
axis tight
% Compare to the original
figure
imagesc(A)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!