nick_name
nick_name

Reputation: 1373

MATLAB - Changing the Tick Mark Values When Plotting a Matrix

Currently, the axises are tick marked with values representing their index in a matrix. I want to relabel them to correspond to the points in my mesh grid. There is a one-to-one correspondance, so this mapping is indeed plausible. How can I accomplish this?

[x z] = meshgrid(-10:.25:10,-10:.25:10);
B = zeros(81,81);
for i=1:81
    for j=1:81
        [theta,phi,r] = cart2sph(x(i,j),0,z(i,j));
        Px = (1/16)*(r.^4).*exp(-r).*(sin(pi/2-phi).^2).*(cos(theta).^2);
        B(i,j)=Px;
    end
end

subplot(3,3,1);
imagesc(B);

Figure 1: Axes with undesirable labels.

Upvotes: 1

Views: 547

Answers (1)

nick_name
nick_name

Reputation: 1373

Just add arguments to imagesc() as shown below. You can specify the x and y ranges.

x_range = [-10:.25:10];
z_range = x_range;
[x z] = meshgrid(-10:.25:10,-10:.25:10);
B = zeros(81,81);
for i=1:81
    for j=1:81
        [theta,phi,r] = cart2sph(x(i,j),0,z(i,j));
        Px = (1/16)*(r.^4).*exp(-r).*(sin(pi/2-phi).^2).*(cos(theta).^2);
        B(i,j)=Px;
    end
end

subplot(3,3,1);
imagesc(x_range,z_range,B);

Upvotes: 2

Related Questions