want the Negative data be ignored and become postive

31 次查看(过去 30 天)
I have for loop and I want to ignore the negative values in y-axis
plot(x+k,y+k,'Color');end
  5 个评论
Najiya Omar
Najiya Omar 2018-1-23
Thank you my problem is to change the negative values to positive
Stephen23
Stephen23 2018-1-23
编辑:Stephen23 2018-1-23
"Thank you my problem is to change the negative values to positive"
Use abs.

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2018-1-23
temp = y+k;
temp(temp < 0) = nan;
plot(x+k, temp);

Star Strider
Star Strider 2018-1-23
Another option:
plot(x+k,y+k,'Color')
set(gca, 'YLim',[0 max(ylim)])
  4 个评论
Walter Roberson
Walter Roberson 2018-1-23
The solution posted in this Answer just cuts off the plot so nothing with a negative y is plotted. That was a valid interpretation when you originally asked the question, in the time before you indicated you wanted the negative values to change sign.
Star Strider
Star Strider 2018-1-23
Your original Question simply wanted to eliminate the negative y-values. This plots y from 0 to whatever the maximum value of the y-axis limit is.
You have changed your Question, now saying that you want to change the negative values to positive. I would not recommend doing that because it distorts your data. If you are only supposed to have positive results from your calculations, you will need to find the error that produces the negative values, and correct it.
Also, did you see my Answer to your previous Question Elemination in for loop? Did it do what you want?

请先登录,再进行评论。

类别

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