Search code examples
matlabaxissurf

Rescale x-Axis in surf plot


I have a 1024 by 100 matrix. When I use the function surf it plots the data with axis limit 0 to 1024 for x, 0 to 100 for y and the entries of the matrix as z values (as expected). Now I want to keep everything in the plot the same, except for the x axis limits: I want to have them from 400 to 1000 i.e. I want to rescale the x axis. I don't want to start at the 400th entry and stop at the 1000th. I want to have the first entry to correstpond to 400 and the last one to 1000th. In other words change only the labels of the x axis to go from 400 to 1000 and not from 0 to 1024. Is there a simple way to do that or do I need to use meshgrid?


Solution

  • You probably want something like this:

    %Example data
    [X,Y] = meshgrid(1:0.1:8,1:0.1:8);
    Z = sin(X)+cos(Y);
    %Example plot
    surf(X,Y,Z)
    
    %We change the XTick Labels
    xt = get(gca,'XTick'); %get the actual xtick value
    xl = arrayfun(@num2str, linspace(400,1000,length(xt)), 'Uniform', false).';
    set(gca,'XTickLabel',xl) %set the news xtick labels.
    

    With set(gca,'XTickLabel',your_cell_of_string) you can change the actual XTickLabel with some news string, xl and xt must have the same size.