Use of ".mat"-file and objects/matrices therein to create plots

Hi all,
I want to do the following:
I have a file "xy_results.mat", which has inside of it among others an object called "oo_", and therein among others an object called "irfs". In "irfs" I have several vectors {y_a, c_a, i_a, y_b,c_b, i_b,...}. Now I would like to have a loop which creates subplots for all {y_a,y_b,...}, {c_a,c_b,...} etc and also subplots in another figure which contains all elements of {_a}, {_b}, etc.
Who can help me on this? Doing it manually I tried something like
load xy_results.mat
HOR=1:1:40;
plot(HOR,oo_.irfs.y_a,'y',HOR,oo_.irfs.c_a,'b')
which works fine, but as I have many entries in irfs and many differens ".mat" I'd prefer to have a loop that does the copy paste for me.
Could somebody please help me out on this issue, I would appreciate your help very much! Best, Philipp

Answers (1)

1 Comment

Thank you very much for the links but I must confess that yet Im not really satisfied with your answer. I know how to apply something like
for n = 1:10
eval(['irf_',nd(n,:), ' = oo_.irfs'])
end
but this doesnt really bring me anywhere. As my matrices are not numbered from like 1 to 10, but rather have extensions _a,_b, ... I am clueless. I tried something like
nd =strvcat('a','b',...); %shocks var =strvcat('y_',c_','i_',...); %variables color=strvcat('y','b','g','r','c','m','w'); %colors
but then how do I go on to have a loop like
for i=1:5 subplot(2,3,i) for j=1:5 [eval(['irf' num2str(j) '.' var(i,:)])]; hold on plot(1:25,[eval(['irf' num2str(j) '.' var(i,:)])],color(j),'LineWidth',1) title(['Response of ' var(i,:)] ) end end
Please help me out with a code, rather than a link that puzzles me even further. Best, Philipp

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 27 Feb 2013

Community Treasure Hunt

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

Start Hunting!