|
thank you walter,
varnames{i} = deblank(txt(i,:));
title(varnames{i});
worked perfectly!
Walter Roberson <roberson@hushmail.com> wrote in message <i7tbj6$lvp$1@canopus.cc.umanitoba.ca>...
> On 10-09-28 12:53 PM, blubb wrote:
>
> > i have argument-names saved as an character array.
> > i plotted some data and now i want to the names of the arguments (saved
> > in an array) as plot titles.
> >
> > at the moment my code looks like this schematically:
> >
> > for i=1:N
> > varnames(:,i) = cellstr(txt(:,i));
> > plot(X(:,i),Y(:,i));
> > title(['print -dtiff plot_' num2str(i)]); % but i prefer the argument
> > name as the plot title instead of only the number of the counter i. how
> > do i get matlab to use the names saved in txt to use as a plot title?
>
> To double check to be sure we are talking about the same thing: currently your
> ['print -dtiff plot_' num2str(i)] expression inside of your title() call will
> simply construct a character string such as 'print -dtiff plot_1' . I can't
> think of any reason you would want to use that particular string, which looks
> so much like a matlab command, unless your intention is to remind the user
> what they have to do to print that particular plot -- but if that were the
> case, then it would seem to make more sense to add a control to the plot to
> request printing .
>
>
> cellstr() returns a cell array, with the expectation that the input to it is a
> character array. If txt(:,i) does not happen to be a cell array, then it is
> going to result in a column vector of text, and cellstr() of that would result
> in a cell array containing strings each of one character. That doesn't sound
> like it would be what you want... at the very least it would not be
> generalizable to multi-character variable names.
>
> Because cellstr() returns a cell array, if varnames() was not pre-allocated,
> then by the end of the loop, varnames would end up being a 1 x N cell array.
>
> Your question says that you prefer "the" argument name, but your varnames
> logic is constructing a column vector of single-character strings, making it
> questionable as to which one is "the" argument name for your purposes.
>
> Your code would make more sense if your txt(:,i) reference were txt(i,:)
> If that were the case, then I would replace that line with
>
> varnames{i} = deblank(txt(i,:));
>
> and then
>
> title(varnames{i})
>
> or something similar, such as
>
> title(['pH 30 minutes after adding 7 mol of ', varnames{i}, ...
> ' to Cherry Garcia ice cream']);
|