Scatterplot with condition on another matrix
Show older comments
Hi I have 2 matrices A and B that are 1x98 that I want to plot using scatterplot. I also have the third matrix C that is used to separate the data.
So if A<=C, the dots should appear blue, and if A>C, the dots should appear black.
How do I set that up, and what the code should look like?
Thanks. I need this as soon as possible.
6 Comments
Fabio Freschi
on 9 Sep 2019
Can you share the data in a mat file?
Chi Pham
on 9 Sep 2019
That doesn't match up with anything you've written previously...there's no A,B, nor C array in that .mat file; only a cell array with a bunch of cellstr in first four columns and two numeric columns as the last two; the latter of which is replete with many NaN.
Nor are any of the variables in the above snippet defined by load 'ing the attached .mat file.
Chi Pham
on 10 Sep 2019
dpb
on 10 Sep 2019
Well, we only know what you tell us...we don't know the magic correlations. :)
See updated Answer...
dpb
on 10 Sep 2019
"but it does not seem like it separates the 2 conditions"
Because the syntax is incorrect for the if test. You've written the two variables w/o the subscript which returns a logical vector of the same size as they. if is true iff all elements of the condition are true; see the documenation for IF for details.
Also, even with that corrected, you've done the same thing in the argument to scatter; each time you call it, it will do the full vectors with the particular color...excepting since only the false case will ever actually execute, your code draws the same scatter plot over and over length(index_of_max_data) times, always with the same result.
See the previous Answer for "the MATLAB way"
Accepted Answer
More Answers (0)
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!