From: Rob Newman on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hn97g6$en$1(a)canopus.cc.umanitoba.ca>...
>
> Sorry, minor correction:
>
> set(gca, 'YTickLabel', num2str(get(gca, 'YTick').'));
>
> Notice the addition of the .' after the get() call; it transforms the row
> vector into a column vector so that num2str() will produce a column of
> individual labels instead of a combined single row of labels.

Great! That worked! Thanks so much. So, in regards to my other question, if I want to append the string 'nm/sec' to the very first value (-500000 to -500000 nm/sec) and also to the very last value (500000 to 500000 nm/sec) on the Y-axis, can I just get the first and last values of that column vector, such as:

mytitles = num2str(get(gca, 'YTick').)
title_length = length(mytitles)

mytitles(1) = [ mytitles(1) 'nm/sec' ]

mytitles(title_length) = [ mytitles(title_length) 'nm/sec' ]

% Then do the row to column vector transform
my_new_column_titles = mytitles'

% Now set the YTickLabels
set(gca, 'YTickLabel', my_new_column_titles )

Am I way off base here?
(Apologies for the pseudo code - I am more used to coding in Python and Perl)

Regards,
- Rob
From: Walter Roberson on
Rob Newman wrote:

> Great! That worked! Thanks so much. So, in regards to my other question,
> if I want to append the string 'nm/sec' to the very first value (-500000
> to -500000 nm/sec) and also to the very last value (500000 to 500000
> nm/sec) on the Y-axis, can I just get the first and last values of that
> column vector, such as:
>
> mytitles = num2str(get(gca, 'YTick').)
> title_length = length(mytitles)
>
> mytitles(1) = [ mytitles(1) 'nm/sec' ]
> mytitles(title_length) = [ mytitles(title_length) 'nm/sec' ]
>
> % Then do the row to column vector transform
> my_new_column_titles = mytitles'
>
> % Now set the YTickLabels
> set(gca, 'YTickLabel', my_new_column_titles )
>
> Am I way off base here?

Yah, that won't work for a number of reasons.

mytitles = cellstr(num2str(get(gca,'YTick').'));
mytitles{1} = [mytitles{1} ' nm/sec'];
mytitles{end} = [mytitles{end} ' nm/sec'];
set(gca, 'YTickLabel', mytitles);

However, the numbers then won't line up unless you have

set(gca,'YAxisLocation', 'right')


To get the tick label numbers to line up on the left,

set(gca, 'YTickLabel', char(mytitles), 'FontName', 'Courier')


From: Rob Newman on
Walter Roberson <roberson(a)hushmail.com> wrote in message

> Yah, that won't work for a number of reasons.
>
> mytitles = cellstr(num2str(get(gca,'YTick').'));
> mytitles{1} = [mytitles{1} ' nm/sec'];
> mytitles{end} = [mytitles{end} ' nm/sec'];
> set(gca, 'YTickLabel', mytitles);
>
> However, the numbers then won't line up unless you have
>
> set(gca,'YAxisLocation', 'right')
>
>
> To get the tick label numbers to line up on the left,
>
> set(gca, 'YTickLabel', char(mytitles), 'FontName', 'Courier')
>

Hi Walter,

Thanks so much for all the help. All the above worked, and I have learned more about Matlab cells and vector structures than I knew before. Much obliged!!!!

I think I am good for now. All the best,
- Rob