필터 지우기
필터 지우기

Loop through a cell array to use plot3

조회 수: 4 (최근 30일)
Marie P.
Marie P. 2020년 12월 8일
편집: Marie P. 2020년 12월 8일
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.

채택된 답변

Ive J
Ive J 2020년 12월 8일
편집: Ive J 2020년 12월 8일
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
Marie P.
Marie P. 2020년 12월 8일
I did and I just added a grid to the plot with the first data set
Ive J
Ive J 2020년 12월 8일
편집: Ive J 2020년 12월 8일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by