フィルターのクリア

How can I change the title of variables ?

1 回表示 (過去 30 日間)
fiko bil
fiko bil 2019 年 11 月 15 日
編集済み: the cyclist 2019 年 11 月 15 日
Hello, I am having problem when I want to change the title of the variables to be seen on the each plot.
for ii=1:length(ending_cell)
HOR=1:options_.irf;
var={'yhat', 'URhat', 'chat', 'what'};
figure
for jj=1:length(var)
for jj=1:length(var)
subplot(2,2,jj)
eval(['irf1.' var{1,jj},ending_cell{1,ii}]);
eval(['irf2.' var{1,jj},ending_cell{1,ii}]);
hold on
plot(HOR,[eval(['irf1.' var{1,jj},ending_cell{1,ii}])],'-k',HOR,[eval(['irf2.' var{1,jj},ending_cell{1,ii}])],'--r','LineWidth',2) ;
axis tight
legend('No labor friction(JQ)','Labor f');
%title(['Output','Unemployment','Consumption','Wage'])
title([var{1,jj}] )
end
end
end
Any idea how I can chnage it ?
Thank you
  2 件のコメント
ME
ME 2019 年 11 月 15 日
Can you possibly let us know what exactly you want this to output? This will make it easier for people to help.
Stephen23
Stephen23 2019 年 11 月 15 日
編集済み: Stephen23 2019 年 11 月 15 日
Do NOT use eval for accessing fields of a structure, simply use dynamic fieldnames instead:
And of course do NOT access variable names dynamically:
Your code would be a lot simpler, easier to debug,and more efficient if you avoided eval.

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

回答 (2 件)

fiko bil
fiko bil 2019 年 11 月 15 日
Than you for the reply.
Well, I just simply want to change the name of variables yhat, URhat, chat, what to be Output, Unemployment, Consumption, wage. They need to be appear as the title of the plots I get.
There is no problem for code to work I just wanted to make some changes.
Thank you
  1 件のコメント
Adam
Adam 2019 年 11 月 15 日
編集済み: Adam 2019 年 11 月 15 日
There is no problem for code to work I just wanted to make some changes.
If you have a problem making changes that often implies there is a problem with the code! Easy to use code is also easy to change and understand. I can't understand what on earth your code is doing through all the evals in order to make a suggestion that would, in all likelihood, be trivial with simpler code.

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


ME
ME 2019 年 11 月 15 日
Output=yhat;
Unemployment=URhat;
Consumption=chat;
wage=what;
You can always also use:
clear vars yhat URhat chat what
if you want to remove the duplicates with the old naming.
I may be missing something, so if this isn't what you want then let me know and I'll see what I can do to help.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by