set axes limit manual

3 views (last 30 days)
Maria Jose Legaz
Maria Jose Legaz on 18 Sep 2021
Answered: Cris LaPierre on 18 Sep 2021
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

Answers (3)

Cris LaPierre
Cris LaPierre on 18 Sep 2021
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)"])

Maria Jose Legaz
Maria Jose Legaz on 18 Sep 2021
Hello Cris.
Thank you for answering me.
I attach the code
I do not specific any value for X and Y
Could you tell me in which part of the code I have to do the specification? and what have to write?
x value goes from 2 to 11
y values goes from 0 to 5.5 in steps of 0.5
Thank you again
This is the code:
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
imagesc(B)
colorbar

Cris LaPierre
Cris LaPierre on 18 Sep 2021
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)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!