Help-Plot of two vectors - scatter plot with two subsamples??

7 次查看(过去 30 天)
Hi all,
I have the following question:
I have two column vectors X (min value= -0.5; max value= 1.1; 1000 observations) Y (min value =-0.7; max value= 3; 1000 observations)
I would like to perform the following plot. Plot a subset of X (for -0.1 to 0.5) on the x-axis and the corresponding observations of Y on the y-axis.
I would like to split the Y observations in two groups around the point X=0, such that I have observations to the left of X=0 and to the right of X=0.I would also like to fit regression lines (lines of best fit) to the left and right of X=0 and compare their slopes. Can anybody help me with this difficult challenge?
Thanks for your time!

采纳的回答

Walter Roberson
Walter Roberson 2012-5-13
availcolors = [1 0 0; 0 1 0]; %arbitrary, red and green
colidx = 1 + (X >= 0); %1 on the left, 2 on the right
colorarray = availcolors(colidx,:); %array of rgb
pointsize = 10; %arbitrary
scatter(X, Y, pointsize, colorarray)

更多回答(1 个)

Jarek
Jarek 2012-5-13
Thank you Walter Roberson for taking the time to look through my problem.
That is great!
Still, two issues remaining:
1. How to plot a subset of X (for -0.1 to 0.5) on the x-axis and the corresponding observations of Y on the y-axis.
2. I would also like to fit regression lines (lines of best fit) to the left and right of X=0 and compare their slopes.
It would be great if somebody could help me on this?
Thanks for your time and effort!
  2 个评论
Walter Roberson
Walter Roberson 2012-5-13
in_subset = (X >= -0.1 & X <= 0.5);
X = X(in_subset);
Y = Y(in_subset);
Regression lines you should now be able to figure out for yourself using logical indexing.
Jarek
Jarek 2012-5-13
Thank you Walter Roberson for the swift reply, this is really cool!!
As you can see, I am completely new to matlab.
I have found the Basic Fitting sub-menu in Tools-menu, however it fits only one line for the whole sample, and I need two separate lines for X=[-0.1 to 0] and [0 to 0.5].
Unfortunately, I couldn’t figure out how this logical indexing works, still trying though.
It could be great if you could help on this!
Thanks again for your time and effort!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by