How to populate tiles using the next tile command with a variable number of data and a variable number of plots

15 次查看(过去 30 天)
I would like to prepare a code where I can populate tiles using the next tile command with a variable number of data and a variable number of plots using a for loop routine based on the number of variables. For example, here I have prepared displacement, velocity and acceleration of 3 different data sets and I was able to plot them in each individual tile. But the problem is that I had to do this manually instead of doing it with a for loop routine which I can enter the information of not only 3 variables but more variables and have the next tile code simply do it automatically for you without having to enter manually the number of variables.

回答(1 个)

Mathieu NOE
Mathieu NOE 2025-9-17,7:54
hello
seems to me the question is more about how to prepare / concatenate your individual data -
either something very simple and basic like below or better use structures or cell arrays (maybe you already use it in your code)
% create some dummy data
nb_vars = 3 ; % accel / vel / displ
n = 5; % how many channels / data per variable
samples = 100;
x = linspace(0,samples)';
for k=1:n
accel(:,k) = sin(x/k+1)+k;
vel(:,k) = cos(x/k+2)-k;
disp(:,k) = -sin(x/k+3)*k;
leg{k} = ['channel ' num2str(k)];
end
%% main code
% Create layout and plots
for ii = 1:nb_vars
if ii == 1
data = accel;
titl = 'Accel';
elseif ii == 2
data = vel;
titl = 'Velocity';
elseif ii == 3
data = disp;
titl = 'Displ';
end
nexttile
plot(x,data)
title(titl)
legend(leg)
end

类别

Help CenterFile Exchange 中查找有关 Beamforming and Direction of Arrival Estimation 的更多信息

产品


版本

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by