How to populate tiles using the next tile command with a variable number of data and a variable number of plots
    13 views (last 30 days)
  
       Show older comments
    
    juan sanchez
 on 17 Sep 2025
  
    
    
    
    
    Commented: juan sanchez
 on 26 Oct 2025 at 5:22
            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.

0 Comments
Accepted Answer
  Mathieu NOE
      
 on 17 Sep 2025
        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
More Answers (0)
See Also
Categories
				Find more on Uncertainty Analysis 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!

