Plot segments of an array with NaN using a for loop
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I got an array with NaN. I want to plot, step-by-step, those segments of integers, that exceed a threshold and flanked by NaN, using a for loop.
Example:
Threshold=5
A=[NaN 1 2 3 4 4 3 1 NaN 2 4 5 10 11 12 14 13 11 7 5 3 NaN 2 3 7 15 20 25 17 13 9 5 1 NaN]
So, I want the loop to take the second segment of the integers flanked by NaN (2 - 3) and plot them. Then, I will do some operations with the plot, and I will continue with the loop using a wait(X) for the third segmentt (2 - 1).
The array always starts with a NaN, and finishes with an NaN.
for i = 1:length(A)
% code for getting the plot and make the operation
wait(next_plot)
end
At least, if I can plot the second and the third segment together skipping the first one, I would save my day.
Best,
Jose
댓글 수: 0
채택된 답변
dpb
2021년 3월 2일
편집: dpb
2021년 3월 2일
Rough outline to accomplish --
ix=find(isnan(A)); ix=ix(2:end); % find the NaN sections, ignore first
for i=1:numel(ix)-1 % over the groups
subplot(2,1,i); % just to show the separate pieces;
x=ix(i):ix(i+1); % set the x values to match
B=A(x); % select the portion wanted from A this group
B(B<=Threshold)=nan; % don't plot those <= Threshold
plot(x,B,'*-') % plot verus original ordinal position
end
If only want the values above the threshold, then delete those below (or select only those above) instead and the corresponding x values to match.
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Time Series Events에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!