Changing step size of a graph

I'm currently making a function that creates a graph for a given set of x and y data and I need to scale my X axis so that the step values are by 5 instead of the 10 that it creates automatically. How would I go about doing that? My current code is below.
file = load('SampleXYData.mat');
xData = file.xData;
yData = file.yData;
myFig = gcf;
myAx = axes(myFig);
myPlot = scatter(myAx, xData, yData);
myPlot.Marker = 'x';
myAx.Title.String = 'Scatter Plot';
myAx.YAxis.Label.String = 'Y';
myAx.XAxis.Label.String = 'X';
myAx.Box = 'on';
endAt = length(myAx.XAxis.TickLabels);
for i = 1:endAt
cVal = str2double(myAx.XAxis.TickLabels{i});
if mod(cVal , 10) == 0
myAx.XAxis.TickLabels{i} = ['\bf', myAx.XAxis.TickLabels{i}];
end
end

3 commentaires

DGM
DGM le 22 Mar 2021
I'm assuming you mean you want to change the tick mark spacing.
You should just be able to set the axes Xtick property.
myAx.XTick=mytickvector;
or you can use set():
set(myAx,'xtick',mytickvector);
Of course, I don't know exactly what you're doing with the ticklabels.
How would I write a vector that would increase by 5 until the end? I know how to set it at a given value, but I want to have it works for varying sets of data.
I tried this, but it gave me an error saying "the end operator must be used within an array index expression'
myAx.XTick = (1:5:end)
DGM
DGM le 22 Mar 2021
Assuming we want the same extreme values:
myAx.XTick=myAx.XTick(1):5:myAx.XTick(end);

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Commenté :

DGM
le 22 Mar 2021

Community Treasure Hunt

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

Start Hunting!

Translated by