- As mentioned in the question to get 3×3 tiledlayout, but in the code it is initialized for 5×5
- The main reason for second error is tiledlayout should be initialized outside the for loop
- The reason for first error might be data sent to function is not handled properly in for loop.
Add sets of graph onto tiledlayout
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am using a nested for loop to try and create a 3-3 tiledlayout. In the outer for loop, i get the information and in the inner for-loop I am iterating through the information to create 3 plots.
The first error that I am getting is that I want to print 3 graphs in one row but it is only letting me print two.
The second error is that it resets the graphs everytime I go to the next iteration in the outerloop, Instead of keeping the graphs intact.
Here is my code. Please Help, Thank You!
function idek(xy_cell)
position = 1;
global num_drones
M_rows = num_drones;
%RUN LENGTH OF EXTRACTED CELL
for i = 1:length(xy_cell)
tiledlayout(5, 5);
ith_drone_xy = xy_cell{i};
x_loc = ith_drone_xy(:,1);
y_loc = ith_drone_xy(:,2);
for t = 1:length(x_loc)
x = x_loc(t);
y = y_loc(t);
clf
nexttile;
plot(x, y, 'go', 'LineWidth', 1, 'MarkerSize', 10)
hold on
plot(x_loc, y_loc, 'LineWidth', .5)
xlabel('x')
ylabel('y')
title(['Drone Trajectory at ', num2str(t), ' Seconds'])
nexttile;
plot(t, x, 'go', 'LineWidth', 1, 'MarkerSize', 10)
hold on
plot(x_loc, 'LineWidth', .5)
xlabel('Time')
ylabel('x-Location')
title(['Drone x-Location at ', num2str(t), ' Seconds'])
nexttile;
plot(t, y, 'go', 'LineWidth', 1, 'MarkerSize', 10)
hold on
plot(y_loc, 'LineWidth', .5)
xlabel('Time')
ylabel('y-Location')
title(['Drone y-Location at ', num2str(t), ' Seconds'])
% drawnow
% pause(0.3)
movieVector(t) = getframe;
end
hold('on')
nexttile;
end
0 comentarios
Respuestas (1)
Monisha Nalluru
el 12 de Ag. de 2020
The reason for errors obtained in above function
You can use something like below:
a={{[1,2,3,4],[5,6,7,8]},{[7,8,9,10],[11,12,13,14]}};
tiledlayout(2,2)
for i=1:numel(a)
ele=a{1,i};
for j=1:numel(ele)
newele=ele{1,j};
nexttile
plot(newele);
end
end
You can customize accordingly.
0 comentarios
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!