changing the X tick label
65 views (last 30 days)
hi everybody, I am looking for a way to change the X tick labels not by hand , because it's a lot of ticks to change' i want to do it by loop , I have to vectors a=[ 1 2 3 4 5] b = [ 10 9 8 7 6] and my X tick label now is 1 2 3 4 5, but i want it to be : 1-10 2-9 3-8 4-7 5-6, I guess it involves somehow num2str function but I am not sure how or if..
Walter Roberson on 30 Nov 2011
set(gca, 'XTickLabel', a-b)
Or if you prefer,
set(gca, 'XTickLabel', str2num(a(:)-b(:)) )
It is important for this purpose that the expression passed to str2num be a column vector rather than a row vector.
More Answers (2)
Matt Tearle on 30 Nov 2011
If a and b are numeric, then
lbls = strcat(strtrim(cellstr(num2str(a(:)))),'-',strtrim(cellstr(num2str(b(:)))))
Ugly, but it gets rid of any excess spaces.