want the Negative data be ignored and become postive

I have for loop and I want to ignore the negative values in y-axis
plot(x+k,y+k,'Color');end

5 Comments

Can you show us the loop code, and tell us what the sizes of the variables are?
if true
l =0.1:0.1:1.0;
N=numel(l);
i = 1;
for k=1:N
x(i) = a(1);
y(i) = a(10);
i = i + 1;
plot(x+k,y+k,'Color');
end
Each of your plot() is going to overwrite the previous plot because you have no 'hold on'
Each iteration through, you are going to be plotting everything in x and y, which is going to get a longer and longer line as you go.
You are not going to see anything other than the final plot because you do not have any drawnow() or pause()
When you pass the option 'Color' to plot(), you need to also pass in a color specification.
Thank you my problem is to change the negative values to positive
"Thank you my problem is to change the negative values to positive"
Use abs.

Sign in to comment.

Answers (2)

temp = y+k;
temp(temp < 0) = nan;
plot(x+k, temp);

2 Comments

I want them to become positive, same values just change the sign.

Sign in to comment.

Another option:
plot(x+k,y+k,'Color')
set(gca, 'YLim',[0 max(ylim)])

4 Comments

I want them to become positive, same values just change the sign.
@ Star Strider, what is the command expected to give.
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.
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?

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Asked:

on 23 Jan 2018

Commented:

on 23 Jan 2018

Community Treasure Hunt

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

Start Hunting!