Scatterplot with condition on another matrix
显示 更早的评论
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 个评论
Fabio Freschi
2019-9-9
Can you share the data in a mat file?
Chi Pham
2019-9-9
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
2019-9-10
dpb
2019-9-10
Well, we only know what you tell us...we don't know the magic correlations. :)
See updated Answer...
dpb
2019-9-10
"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"
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!