How to produce a subplots for each iteration?
10 ビュー (過去 30 日間)
表示 古いコメント
Hi everyone,
My reuqire to generate plot for each iteration (either as individula or as a group 5 or 10 on each figure). For few interation, if condition not satisify the plot should be blink with iternation number so i can visulize where is something wrong.
Here is my script:
clear all
clc
% BELOW SCRIPT IS FOR MULTIPLE DAYS CALCULATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % ...........Dataset1 ............%
cd_ev=readmatrix('time.csv'); %
ev_time=datenum(cd_ev(:,1),cd_ev(:,2),cd_ev(:,3),cd_ev(:,4),cd_ev(:,5),cd_ev(:,6));
CE_M=ev_time';
for jj=1:145
b=CE_M(:,jj);
aa(jj)= addtodate(b, 5, 'day');
bb(jj)= addtodate(b, -5, 'day');
end
CE_U=aa;
CE_L=bb;
%
% % ------------ Data Set 2 -------------%
%
d_tid=readmatrix('TID.csv'); %
d_tid(1,:) = [];
d_tid(:,1) = [];
s=d_tid;
t1=datenum(s(:,1),s(:,2),s(:,3),s(:,4),s(:,5),s(:,6));
t_d=[t1 d_tid(:,7)];
%------------- Data Set 3 --------------%
d_ven=readmatrix('VENT.csv');
d_ven(1,:) = [];
d_ven(:,1) = [];
ss=d_ven;
ts=datenum(ss(:,1),ss(:,2),ss(:,3),ss(:,4),ss(:,5),ss(:,6));
v_d=[ts d_ven(:,7)];
% ---------- Data selection for a particular event ---------%
for kk=1:110
s2=t_d(t_d(:,1)>= CE_M(kk) & t_d(:,1)<= CE_U(kk),:);
s1=v_d(v_d(:,1)>= CE_M(kk) & v_d(:,1)<= CE_U(kk),:);
if length(s1) ~= length(s2)
continue;
end
S=[s1 s2];
t=S(:, 1);
t=(t-t(1));
ser1=S(:, 2)-mean(S(:,2));
ser2=S(:, 4)-mean(S(:,4));
N=length(t);
dt=(t(end)-t(1))/(N-1);
fs=1/dt; fNyq=fs/2;
f1=1; f2=4;
[z,p,k]=butter(4,[f1,f2]/fNyq,'bandpass');
[sos,g]=zp2sos(z,p,k);
y1=filtfilt(sos,g,ser1);
y2=filtfilt(sos,g,ser2);
% %--------- Zero crossing time --------%
%
zci = @(v) find(diff(sign(v))>0);
izc1=zci(y1);
izc2=zci(y2);
ZeroX = @(x0,y0,x1,y1) x0 - (y0.*(x0 - x1))./(y0 - y1); % Interpolated x value for Zero-Crossing
ZT1 = ZeroX(t(izc1),y1(izc1),t(izc1+1),y1(izc1+1));
ZT2 = ZeroX(t(izc2),y2(izc2),t(izc2+1),y2(izc2+1));
%
if length(ZT1)==length(ZT2)
tzcd=ZT1-ZT2; %zero crossing time differences
elseif length(ZT1)==length(ZT2)-1
tzcd=ZT1-ZT2(1:end-1); %zero crossing time differences
elseif length(ZT1)-1==length(ZT2)
tzcd=ZT1(2:end)-ZT2; %zero crossing time differences
end
fdom=(length(ZT2)-1)/(ZT2(end)-ZT2(1));
phz=360*fdom*tzcd; %phase lag of y1 relative to y2 (degrees)
ww=1:length(tzcd);
figure(); plot(ww,phz,'-rx');
xlabel('Time (days)'); ylabel('Lag (degrees)'); title('Phase Lag v. Time')
ylim([0,360]); set(gca,'ytick',0:90:360); grid on
end
採用された回答
Image Analyst
2022 年 10 月 15 日
編集済み: Image Analyst
2022 年 10 月 15 日
Try this:
for kk = 1 : 27 % 110
needNewFigure = mod(kk-1, 9) + 1;
if needNewFigure == 1
figure;
sgtitle(sprintf('Plots %d through %d', kk, kk+8));
end
% Code to generate something to plot, then...
% Show plots in a 3 by 3 grid
subplot(3, 3, needNewFigure)
drawnow;
end
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Find more on Digital Filtering in Help Center and File Exchange
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!