From: Johannes Buechler on
Hi,

is it possible in Matlab to create a name of an object (like an axis handle or a simple variable) using another as its name, or part of its name?

Example: I have a number of subplots to draw. The respective axes handles are named ax1n, with <n> the number of the subplot. <n> depends on the input data and is not fixed.

So I'd like to use a loop with these handles, like
for i_SubPlot=1:NumberOfSubplots
for j_Curve=1:numel(Data{i_SubPlot})
semilogx(ax1<i_SubPlot>, All.XAxis, Data{i_Subplot}{j_Curve}, 'LineWidth', 2);
...
end
end

Is this possible?

Thanks and best regards Johannes
From: Ross W on
"Johannes Buechler" <jb_spam(a)gmx.DELnet> wrote in message <i40jut$7b0$1(a)fred.mathworks.com>...
> Hi,
>
> is it possible in Matlab to create a name of an object (like an axis handle or a simple variable) using another as its name, or part of its name?
>
> Example: I have a number of subplots to draw. The respective axes handles are named ax1n, with <n> the number of the subplot. <n> depends on the input data and is not fixed.
>
> So I'd like to use a loop with these handles, like
> for i_SubPlot=1:NumberOfSubplots
> for j_Curve=1:numel(Data{i_SubPlot})
> semilogx(ax1<i_SubPlot>, All.XAxis, Data{i_Subplot}{j_Curve}, 'LineWidth', 2);
> ...
> end
> end
>
> Is this possible?
>
> Thanks and best regards Johannes

Hi

The best solution is not to do this. Store the axis handles in a vector, and address them as ax1(n).

But if you really really have to, use eval

For details, see http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

Ross
From: Johannes Buechler on
"Ross W" <rosswoodskiwi(a)hotmail.com> wrote in message <i40m0j$gof$1(a)fred.mathworks.com>...

> The best solution is not to do this. Store the axis handles in a vector, and address them as ax1(n).

This is indeed a much better way - thanks Ross!
It did not yet occur to me to use handle vectors.

New code:
for i=1:NumbOfSubplots
axh(i) = subplot(1,NumbOfSubplots,i);
end

....

for i=1:NumbOfSubplots
for j=1:numel(Data{i})
semilogx(axh(i), All.XAxis, Data{i}{j}, 'LineWidth', 2);
end
end

Thanks again

Johannes