Using string as data for plotting

I have a code that plot data on 4 subplots
I have problem with the labels head_val= {a,b,c,a,b,c,b,c,c}
I need them to be on tick marks as follows:
Subplot (1): a b c ,(3 bars)
Subplot (2): a b c,(3 bars)
Subplot (3): b c,(2 bars)
Subplot (4): c,(1 bar)
------------------------------------------
This code: set(gca, 'XTick', 1:9, 'XTickLabel', (valhead));
distributes the ticks as follows Subplot (1): a b c , Subplot (2): a b c, Subplot (3): a b, Subplot (4): a,
It seems that the gca line loops over the first three strings only
Thanks ---UPDATE---- This is a display to show the difference between what's needed and what I get http://imageshack.us/photo/my-images/13/displayz.jpg/

回答(1 个)

If you only want the labels replicated once, it appears you're going to have issues since you have nine ticks:
From the (doc axes -> axes properties): XTickLabel, YTickLabel, ZTickLabel string Tick labels. A matrix of strings to use as labels for tick marks along the respective axis. These labels replace the numeric labels generated by MATLAB. If you do not specify enough text labels for all the tick marks, MATLAB uses all of the labels specified, then reuses the specified labels
Else just use a cell array to group the labels, something similar to:
head_val= {'a,b,c','a,b,c','b,c','c'};
figure;
for ii = 1:4;
subplot(2,2,ii)
plot(rand(1,10));
set(gca, 'XTick', 1:9, 'XLabel', head_val{ii});
end
Or is the 1:9 not constant as an xtick?

1 个评论

Yes, it's not a constant as an XTick but it's manageable
The issue now is that I get this error "Value must be a handle"
Any help? Thanks!

此问题已关闭。

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by