How to refer the figure name in matlab

55 ビュー (過去 30 日間)
JazzMusic
JazzMusic 2017 年 1 月 2 日
コメント済み: JazzMusic 2017 年 1 月 2 日
Hi, I would like to define a figure and then for that specific figure do some things. Foe example: I would like to vreat a digure say:
h1 = figure('units','normalized','outerposition',[0 0 1 1]);
and then I want for h1 to do for example:
subplot(1,3,1)
plot(N_vec,1./Err(N_vec),sprintf('*%c',colconds(loop)),'LineWidth',5)
hold on
plot(N_vec,1./ErrPV(N_vec),sprintf('*%c',colconds(loop+2)),'LineWidth',5)
hold on
xlabel('Population size','fontsize',20)
ylabel('Error^-2 ','fontsize',20)
legend('OLE','PV','OLE shuffled','PV shuffled','Location','northwest')
The thing is that from loop reasons, h1 is defined far from the above lines. and is not the current figure handel. So I want the above lines to refer specifically for h1. somethong like:
subplot('h1',1,3,1)
plot('h1',N_vec,1./Err(N_vec),sprintf('*%c',colconds(loop)),'LineWidth',5)
hold on
plot('h1',N_vec,1./ErrPV(N_vec),sprintf('*%c',colconds(loop+2)),'LineWidth',5)
hold on
xlabel('h1','Population size','fontsize',20)
ylabel('h1','Error^-2 ','fontsize',20)
legend('h1','OLE','PV','OLE shuffled','PV shuffled','Location','northwest')
But matlab gives error whenever i try to add the name h1 in the specific commands for the figure...
how do I refer the figure handel when I actully want to use it?
Thanks!!

採用された回答

José-Luis
José-Luis 2017 年 1 月 2 日
編集済み: José-Luis 2017 年 1 月 2 日
fH = figure;
dummy = figure;
plot(1:10);
figure(fH); %Make fH current
plot(rand(10,1));
  1 件のコメント
JazzMusic
JazzMusic 2017 年 1 月 2 日
It worked. Thank you!

サインインしてコメントする。

その他の回答 (2 件)

Preethi
Preethi 2017 年 1 月 2 日
hhello,
hope this helps. it sets figure with h1 handle as current figure.
set(groot,'CurrentFigure',h1);

Niels
Niels 2017 年 1 月 2 日
Hi,JazzMusic
did u try
figure(h1)
to set h1 the current figure before u use subplot?
figure(h1)
subplot(1,3,1)
plot(N_vec,1./Err(N_vec),sprintf('*%c',colconds(loop)),'LineWidth',5)
hold on
...
  1 件のコメント
JazzMusic
JazzMusic 2017 年 1 月 2 日
Yes, I did after the first answere here. Thank you for your help! :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by