Borrar filtros
Borrar filtros

Loop through a cell array to use plot3

4 visualizaciones (últimos 30 días)
Marie P.
Marie P. el 8 de Dic. de 2020
Editada: 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.

Respuesta aceptada

Ive J
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
Marie P.
Marie P. el 8 de Dic. de 2020
I did and I just added a grid to the plot with the first data set
Ive J
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by