Plotting selected data possibly with indexing

I have a code using which i solve equations and get the required for plotting. The data is from a physical problem and for that reason, i only need to plot it when a certain variable is less than zero (for the first time). Afterwards the equations dont hold and the whole issue becomes meaningless.
For simplicity i am just listing an example. Kindly let me know how can i have a plot like this with the data below. Note that i only want to plot data while y approaches 0 for the 1st time. (so not all values which are postive).
x = [ 1 2 3 4 5 6 7 8 9 10 11 12];
y = [ 1 4 7 8 6 3 2 -2 -5 7 9 12];

댓글 수: 1

So according to what i understand you want to plot y only when it first reaches 0 so in the above
y = [ 1 4 7 8 6 3 2] % is the part where you want to plot

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

 채택된 답변

madhan ravi
madhan ravi 2020년 8월 28일

0 개 추천

y = cumprod(y > 0) .* y;
y(y == 0) = nan
plot(x, y)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

태그

질문:

2020년 8월 28일

댓글:

2020년 8월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by