Scatter plot - plot different symbols when data is negative

10 ビュー (過去 30 日間)
Jesse
Jesse 2015 年 4 月 28 日
コメント済み: Jesse 2015 年 4 月 28 日
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 件のコメント
Joseph Cheng
Joseph Cheng 2015 年 4 月 28 日
編集済み: Joseph Cheng 2015 年 4 月 28 日
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')
Jesse
Jesse 2015 年 4 月 28 日
Joe,
The "or" really cleared things up. Thank you so much!
-J

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by