Clear Filters
Clear Filters

Loop through a cell array to use plot3

4 views (last 30 days)
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.

Accepted Answer

Ive J
Ive J on 8 Dec 2020
Edited: Ive J on 8 Dec 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 Comments
Marie P.
Marie P. on 8 Dec 2020
I did and I just added a grid to the plot with the first data set
Ive J
Ive J on 8 Dec 2020
Edited: Ive J on 8 Dec 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

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!