Loop through a cell array to use plot3
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
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 Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!