Search code examples
matlabmatlab-figure

Changing tick values of matlab .fig


I have a matlab figure given to me where the x axis values range from 0 to 4500 time steps. Each time step corresponds to 1.8e-8 seconds. I want to convert the ticks to seconds so I have 0,0.0900,0.1800,0.2700,0.3600,0.4500,0.5400,0.6300,0.7200,0.8100 seconds.

Is there a way to do this in the figure plotter? enter image description here


Solution

  • If you don't want to modify the actual data, then once you have opened the .fig file you can change the labels simply by doing

    set(gca, 'XTickLabel' , {'0' '0.09' '0.18' '0.27' '0.36' '0.45' '0.54' '0.63' '0.72' '0.81'})
    

    enter image description here

    If instead you want to modify the data, then after opening the figure file you can first get the handle to the axis with gca, then next get the handle of the plot, and finally get the underlying data and modify it:

    ax1 = gca;                          % get the handle to the axis
    plt1 = get(ax1,'Children');         % get the handle to the plot
    xdata = get(plt1,'XData');          % retrieve x data from the plot
    xdata_seconds = xdata * 1.8e-4;     % convert x data to desired units
    set(plt1, 'XData', xdata_seconds)   % put the new data into the plot