how can i create (generate) the Loop to Access Subfields:
Mostrar comentarios más antiguos
Dears,
I need your help. hocan I access the subfields within eps_G, where eps_G is a structure.
whos myirfs1
Name Size Bytes Class Attributes
myirfs1 1x1 374094 struct
%% disp(fieldnames(myirfs1))
>> disp(fieldnames(myirfs1))
{'eps_CP'}
{'eps_G' }
{'eps_T' }
{'eps_a' }
{'eps_nu'}
{'eps_z' }
% choose 1 or 2 below
shock_type = {'eps_G','eps_nu'};
var_aux = {'log_y','C','pi_ann','B_nominal','B','sp','i_ann','r_real_ann','P'};
var_aux2 = {'log_y_eps_nu','C_eps_nu','pi_ann_eps_nu','B_nominal_eps_nu','B_eps_nu','sp_eps_nu','i_ann_eps_nu','r_real_ann_eps_nu','P_eps_nu'};
var_aux3 = {'eps_G_log_y','eps_G_C','eps_G_pi_ann','eps_G_B_nominal','eps_G_B','eps_G_sp','eps_G_i_ann','eps_G_r_real_ann','eps_G_P'};
%Irfs of monetary and fiscal policy
irf_mon = struct();
irf_fisc = struct();
%% disp(fieldnames(myirfs1))
>> disp(fieldnames(myirfs1))
{'eps_CP'}
{'eps_G' }
{'eps_T' }
{'eps_a' }
{'eps_nu'}
{'eps_z' }
% when i run the following code it is unrecognized. can you suggest me what to do?
for i = 1:numel(var_aux)
irf_mon.(var_aux{i}) = [0,myirfs1(1).(var_aux3{i})]';
irf_fisc.(var_aux{i}) = [0,myirfs1(1).(var_aux3{i})]';
end
Unrecognized field name "log_y_eps_G".
4 comentarios
Gabriel
el 19 de En. de 2025
Editada: Walter Roberson
el 20 de En. de 2025
Gabriel
el 19 de En. de 2025
Editada: Walter Roberson
el 20 de En. de 2025
@Gabriel why do you reinitialize the irf_mon and ir_fisc structures ? They become empty again when you reintialize and erases all previous data.
% Initialize the irf_mon and irf_fisc structures dynamically
%irf_mon = struct(); comment these lines
%irf_fisc = struct(); comment these lines
%%
load('c.mat')
for ii=1:numel(var_list)
subplot(3,3,ii)
v=var_list{ii};
plot(t,myirfs1.(shock_type{1}).(v).data(:,1)/10,'Color',c(10,:),'linewidth',0.7,'LineStyle','--');
The above syntax for structure inside the plot function is not correct. What is data(:,1)/10 ? where is it located ? probably inside c.mat file? Note that var_list is cell array of character variables and not a struct. You need to assign data first to that variable. The correct syntax is
myirfs1.eps_G.logy = data(:,1)/10;
plot(t,myirfs1.eps_G.logy,'Color',c(10,:),'linewidth',0.7,'LineStyle','--')
Gabriel
el 20 de En. de 2025
Respuesta aceptada
Más respuestas (1)
Gabriel
el 21 de En. de 2025
0 votos
Categorías
Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!