How to plot only positive values?

조회 수: 99 (최근 30일)
Yousaf
Yousaf 2020년 2월 6일
답변: Jakob B. Nielsen 2020년 2월 6일
I have a function y=f(x) where 'x' varies within a particular range. For some values of 'x', 'y' gives positive values whereas for some other values 'y' gives negative values. I have two questions:
1.. I have written a table as;
T=table(x,y);
writetable(T,'table.txt');
How can I get a table for only the positive values of 'y' and their corresponding 'x' values?
2.. Using the plot command (without using the table), how can I get a plot for only the positive values of 'y' and their corresponding 'x' values?
Thanks.

답변 (1개)

Jakob B. Nielsen
Jakob B. Nielsen 2020년 2월 6일
You can use logical indexing.
posY=Y(Y>0);
posX=X(Y>0); %the X values for which it is true that the value of Y in the corresponding index is greater than 0.
After that, it is simple to plot(posX,posY);

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by