通过结构数组 Matlab 绘图 - 有趣的案例
Plot Through Struct Array Matlab - The Intresting Case
假设我有一个结构形式:
firstrun.(char(patient(ldy,1))).(char(dypatient(llc,1))).(char(lcpatient(mps,1))).MaxCount;
然后struct变量有长度为i的patient,dypatient也有长度为j等等。这使我们可以拥有一棵树,以便我们可以从现场患者中挑选一个,并挑选与该患者相关的其他领域。
现在,在存储所有值的行尾或最后一个字段中,我有一个包含单个值的字段。最大计数。如下面的代码所示。
对于每个患者,都有第一天或第一天、医院 ID 或位置。在提交的位置,我有一个 MaxCount。
例如,在第二天或第 b 天,我有相同的医院 ID 或位置,但 MaxCount 不同。
我想绘制天数内的最大计数图,请记住这些是奇异值。例如:
firstrun.patientID.dayID_1.hospID_3.MaxCount is only 39
firstrun.patientID.dayID_2.hospID_3.MaxCount is only 22
.
.
.
firstrun.patientID.dayID_i.hospID_j.MaxCount is only 2
The vector to plot is then [39, 22, ...., n]
所以我对几天内每个医院 ID 或位置的就诊次数有不同的绘图。
%% load file
load('/Users/dave/Desktop/firstrun.mat')
if exist('firstrun','var')==1
patient = fieldnames(firstrun);
for ldy = 1:length(patient);
dypatient = fieldnames(firstrun.(char(patient(ldy,1))));
for llc = 1:length(dypatient);
lcpatient = fieldnames(firstrun.(char(patient(ldy,1))).(char(dypatient(llc,1))));
for mps = 1:length(lcpatient);
pspatient = fieldnames(firstrun.(char(patient(ldy,1))).(char(dypatient(llc,1))).(char(lcpatient(mps,1))));
MaxCount = firstrun.(char(patient(ldy,1))).(char(dypatient(llc,1))).(char(lcpatient(mps,1))).MaxCount;
end
end
end
else
disp('Variable does not exist')
end
我如何循环查看同一位患者每天的位置,将相同的位置分组在一起并绘制对每个位置的访问如何变化?
谢谢你的帮助。
下面的代码可以做到
%% load file
load('/Users/dave/Desktop/TrialRun.mat’)
if exist('variablestruct','var')==1
patient = fieldnames(Patesyap);
for ldy = 1:length(patient);
dypatient = fieldnames(DataSynapto.(char(patient(ldy,1))));
for llc = 1:length(dypatient);
lcpatient = fieldnames(DataSynapto.(char(patient(ldy,1))).(char(dypatient(llc,1))));
for mps = 1:length(lcpatient);
pspatient = fieldnames(DataSynapto.(char(patient(ldy,1))).(char(dypatient(llc,1))).(char(lcpatient(mps,1))));
MaxCount = DataSynapto.(char(patient(ldy,1))).(char(dypatient(llc,1))).(char(lcpatient(mps,1))).MaxCount;
TemppatientID = patient(ldy,1);
PlotpatientLoc.(char(TemppatientID))(llc,1).(char(lcpatient(mps,1)))=MaxCount;
end
end
end
else
disp('variablestruct does not exist')
end
if exist('PlotpatientLoc','var')==1
PlotHold = fieldnames(PlotpatientLoc);
for patientIDPlot = 1:length(PlotHold);
mpatient = fieldnames(PlotpatientLoc.(char(PlotHold(patientIDPlot,1))));
for locloos = 1:length(mpatient);
plot((1:max(size([PlotpatientLoc.(char(PlotHold(patientIDPlot,1))).(char(mpatient(locloos,1)))]))),...
[PlotpatientLoc.(char(PlotHold(patientIDPlot,1))).(char(mpatient(locloos,1)))])
hold on
end
end
else
disp('Plot Variable Do not exist')
end
假设我有一个结构形式:
firstrun.(char(patient(ldy,1))).(char(dypatient(llc,1))).(char(lcpatient(mps,1))).MaxCount;
然后struct变量有长度为i的patient,dypatient也有长度为j等等。这使我们可以拥有一棵树,以便我们可以从现场患者中挑选一个,并挑选与该患者相关的其他领域。
现在,在存储所有值的行尾或最后一个字段中,我有一个包含单个值的字段。最大计数。如下面的代码所示。
对于每个患者,都有第一天或第一天、医院 ID 或位置。在提交的位置,我有一个 MaxCount。
例如,在第二天或第 b 天,我有相同的医院 ID 或位置,但 MaxCount 不同。
我想绘制天数内的最大计数图,请记住这些是奇异值。例如:
firstrun.patientID.dayID_1.hospID_3.MaxCount is only 39
firstrun.patientID.dayID_2.hospID_3.MaxCount is only 22
.
.
.
firstrun.patientID.dayID_i.hospID_j.MaxCount is only 2
The vector to plot is then [39, 22, ...., n]
所以我对几天内每个医院 ID 或位置的就诊次数有不同的绘图。
%% load file
load('/Users/dave/Desktop/firstrun.mat')
if exist('firstrun','var')==1
patient = fieldnames(firstrun);
for ldy = 1:length(patient);
dypatient = fieldnames(firstrun.(char(patient(ldy,1))));
for llc = 1:length(dypatient);
lcpatient = fieldnames(firstrun.(char(patient(ldy,1))).(char(dypatient(llc,1))));
for mps = 1:length(lcpatient);
pspatient = fieldnames(firstrun.(char(patient(ldy,1))).(char(dypatient(llc,1))).(char(lcpatient(mps,1))));
MaxCount = firstrun.(char(patient(ldy,1))).(char(dypatient(llc,1))).(char(lcpatient(mps,1))).MaxCount;
end
end
end
else
disp('Variable does not exist')
end
我如何循环查看同一位患者每天的位置,将相同的位置分组在一起并绘制对每个位置的访问如何变化?
谢谢你的帮助。
下面的代码可以做到
%% load file
load('/Users/dave/Desktop/TrialRun.mat’)
if exist('variablestruct','var')==1
patient = fieldnames(Patesyap);
for ldy = 1:length(patient);
dypatient = fieldnames(DataSynapto.(char(patient(ldy,1))));
for llc = 1:length(dypatient);
lcpatient = fieldnames(DataSynapto.(char(patient(ldy,1))).(char(dypatient(llc,1))));
for mps = 1:length(lcpatient);
pspatient = fieldnames(DataSynapto.(char(patient(ldy,1))).(char(dypatient(llc,1))).(char(lcpatient(mps,1))));
MaxCount = DataSynapto.(char(patient(ldy,1))).(char(dypatient(llc,1))).(char(lcpatient(mps,1))).MaxCount;
TemppatientID = patient(ldy,1);
PlotpatientLoc.(char(TemppatientID))(llc,1).(char(lcpatient(mps,1)))=MaxCount;
end
end
end
else
disp('variablestruct does not exist')
end
if exist('PlotpatientLoc','var')==1
PlotHold = fieldnames(PlotpatientLoc);
for patientIDPlot = 1:length(PlotHold);
mpatient = fieldnames(PlotpatientLoc.(char(PlotHold(patientIDPlot,1))));
for locloos = 1:length(mpatient);
plot((1:max(size([PlotpatientLoc.(char(PlotHold(patientIDPlot,1))).(char(mpatient(locloos,1)))]))),...
[PlotpatientLoc.(char(PlotHold(patientIDPlot,1))).(char(mpatient(locloos,1)))])
hold on
end
end
else
disp('Plot Variable Do not exist')
end