stacked plot with 2 time series of different length and spacing
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have 2 time series. Both are different lengths (but they overlap for the first 1300s), and are sampled at different rates. Is there a way to plot this information on a stacked plot?
I want to be able to show the periodicity in the flucctuations so dont really want to plot them in subplot form.
files = dir('*.txt');
N = length(files);
A = cell(1,N);
A2 = cell(1,N);
for ii = 1:max(size(files));
if files(ii).isdir ~=true
fname = files(ii).name;
file = fopen(fname);
A{ii} = cell2mat(textscan(file, '%f %f %f'));
fclose(file);
end
[~,idx] = unique(A{ii}(:,1));
A2{ii} = A{ii}(idx,:);
end
plot(A2{1}(:,2),A2{1}(:,3))
hold on
plot(A2{2}(:,2),A2{2}(:,3))
xlabel('Time (s)')
0 commentaires
Réponses (1)
Star Strider
le 1 Juil 2024
There is a way to use stackedplot with them, however it requires that they be interpolated to the same x-axis vector —
files = dir('*.txt');
for k = 1:numel(files)
A{k} = readmatrix(files(k).name);
Arows(k) = size(A{k},1);
[A11(k),A12(k)] = bounds(A{k}(:,1));
end
A{:}
[Amin,Amax] = bounds([A11(:); A12(:)])
figure
tiledlayout(2,1)
for k = 1:numel(A)
nexttile
semilogy(A{k}(:,1), A{k}(:,2:end))
xlim([Amin, Amax])
grid
end
sgtitle('Using ‘tiledlayout’')
xc = linspace(Amin, Amax, max(Arows));
for k = 1:numel(A)
[A1u,ix] = unique(A{k}(:,1),'stable');
Ay{k} = interp1(A{k}(ix,1), A{k}(ix,2:end), xc);
end
figure
stackedplot(xc, cell2mat(Ay))
grid
sgtitle('Using ‘stackedplot’ & Interpolation')
I would prefer tiledlayout for this, however stackedplot is certainly possible.
.
0 commentaires
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!