jhfrontz
jhfrontz

Reputation: 1385

Repeating sequences in a single matlab plot

Say I have 2 vectors:

a = [1, 2, 3, 4, 5, 6, 7, 8, 9];
b = [1, 3, 5, 7, 9, 7, 5, 3, 1];

I want to plot these vectors against each other, a being X, and b being Y.

However, while I want the plotted point to be in the correct location, I want the actual values shown on the X axis to be a function of the values in a, where the result of the function is repeated over a given period AND I want these values to be sequential along the axis.

For example, say the function for the value to show on the X axis is mod(a - 1, 3) + 1. I would like for the X axis to read something like 1, 2, 3, 1, 2, 3, 1, 2, 3 as in example graph

I have a feeling that some combination of subplot and axes may be required, but I'm not seeing anything obvious in the documentation.

Upvotes: 1

Views: 2792

Answers (2)

nitin
nitin

Reputation: 7358

Try setting the XtickLabels, like so,

>> set(gca,'XTickLabel',{'1','2','3'})

Upvotes: 1

tmpearce
tmpearce

Reputation: 12693

You can set this via the axes properties xtick and xticklabel.

set(gca, 'xtick', a, 'xticklabel', mod(a,3)+1);

This won't give you the ticks you've described, but mod(a-1,3)+1 will. I'm not sure if you wanted the function you gave or the picture you showed, though.

Upvotes: 2

Related Questions