Loop through a cell array to use plot3
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Marie P.
el 8 de Dic. de 2020
Hello, I have the cell arrays jN, jP and jC with the size of 1x20. Each entry holds a n x 1 matrix with a different size of n(each one is +10 entries bigger than the previous one). The data was generated by an ode45 solved for the time. I am trying to plot each dataset of jN, jC and jP together in a plot3 diagramm. Each data set (jC{1,1},jP{1,1} and jN{1,1})belong together and have each the same size, means that I want to plot one graph inlcuding one row of jC, jN and jP and so on until the 20th data sets all together in one diagram. I tried to loop through the entries for a plot 3 diagram but wasn't sucessfull so far.
That's what I did:
for i=1:20
hold on
plot3(jN{1,i},jC{1,i},jP{1,i})
hold off
end
But then I only get the first entries together.
0 comentarios
Respuesta aceptada
Ive J
el 8 de Dic. de 2020
Editada: Ive J
el 8 de Dic. de 2020
Try
for i=1:20
plot3(jN{1,i}, jC{1,i}, jP{1,i})
hold on
end
grid on
hold off
You could also concatenate your vectors and call plot3 once:
jN = vertcat(jN{:}); jC = vertcat(jC{:}); jP = vertcat(jP{:});
plot3(jN, jC, jP); % if wanna show all together
5 comentarios
Ive J
el 8 de Dic. de 2020
Editada: Ive J
el 8 de Dic. de 2020
I reproduced your data structure, and got a 3D plot:
% simulate data points
[jN, jC, jP] = deal(cell(1, 20));
for i = 1:numel(jN)
jN{i} = rand(100 + 10*(i - 1), 1);
jC{i} = rand(100 + 10*(i - 1), 1);
jP{i} = rand(100 + 10*(i - 1), 1);
end
% plot them
for i=1:20
plot3(jN{1,i}, jC{1,i}, jP{1,i})
hold on
end
grid on
hold off
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots 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!