Scatter plot - plot different symbols when data is negative

Greetings all,
I'm trying to differentiate positive and negative data on a plot by representing it with different symbols (i.e. 'o' and 'x', wheere the 'x' would represent negative data), but I'm not having any luck with it.
Here's what I tried:
figure(4)
scatter(sigma2new_Case1,sigma1new_Case1)
while(sigma2new_Case1 < 0)
plot(sigma2new_Case1,sigma1new_Case1,'x');
end
The statement in the "while" - I tried scatter in there but it didn't make any difference - I still get a plot full of 'o's.
Obviously I'm doing something wrong, and if someone could provide suggestions that would be greatly appreciated.
Thanks! Jesse

 채택된 답변

Joseph Cheng
Joseph Cheng 2015년 4월 28일
편집: Joseph Cheng 2015년 4월 28일
well what you're missing is any indexing inside your while loop to check which are less than 0 and basically comparing all of sigma2new_Casel to be <0. You can first figure out which items are <0 and then just plot each one. something like this
y=randi(10,1,20)-5;
x = 1:20;
neg = y<0;
figure,plot(x(~neg),y(~neg),'+',x(neg),y(neg),'o')

댓글 수: 3

Joe,
First, thanks for the response. I made my code very similar to yours:
neg_sig2_Case1 = sigma2new_Case1 < 0; neg_sig1_Case1 = sigma1new_Case1 < 0; plot(sigma2new_Case1(~neg_sig2_Case1),sigma1new_Case1(~neg_sig1_Case1),'+', sigma2new_Case1(neg_sig2_Case1),sigma1new_Case1(neg_sig1_Case1),'o')
But now it's giving me a "Vectors must be the same length" error.
sigma2new_Case1 and sigma1new_Case1 are both 16 x 1 arrays, where sigma1new_Case1 contains negative values, but sigma2new_Case1 is all positive (these cases will change, but for now we'll use this as an example so that I can learn).
neg_sig2_Case1 is a 16x1 but all zeroes since nothing is negative, and neg_sig1_Case1 has 1's in there since some of the values are negative. Is this where the problem lies? Any suggestions on how to correct it?
Thanks again!
so you're looking at data for fully negative values in X and Y. such that only in quadrant 1 of +x and +y will be marked as positive? if that is the case you'll need to perform more logical operators.
y=randi(10,1,20)-5;
x = (1:20)-10;
negy = y<0;
negx = x<0;
neg = negy|negx;
figure,plot(x(~neg),y(~neg),'+',x(neg),y(neg),'o')
Where in the above code looks at which items in each array is negative and performs the logical operator (OR).
My suggestion is to look at the what is trying to be accomplished in my example. are you really trying to plot sigma2new_case1 versus signma1new_case1? in anycase why you're getting the mismatch is that you're not comparing like with like.
For instance in your example sig2 is all positives and sig1 is all negatives.. then you cannot compare the two indexes with each other. as you'll be trying to plot nothing against something.
to break it down with words in pseudo code
plot(sigma2new_Case1(index locations of positive sigma1new_Case1),sigma1new_Case1(index locations of positive sigma1new_Case1),'+', sigma2new_Case1(index locations of negative sigma1new_Case1),sigma1new_Case1(index locations of negative sigma1new_Case1),'o')
Joe,
The "or" really cleared things up. Thank you so much!
-J

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

추가 답변 (0개)

태그

질문:

2015년 4월 28일

댓글:

2015년 4월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by