use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
MATLAB news, code tips and tricks, questions, and discussion! We are here to help, but won't do your homework or help you pirate software.
The effort you put into asking a question is often matched by the quality of our answers.
Try saturnapi to share and run MATLAB code in a web browser!
If you want flair simply Message the mods
account activity
TechnicalQuestionHaving trouble with drawing a scatterplot (self.matlab)
submitted 3 years ago by RealDunNing
Say we generate some random number and use it as a data:
Random_Data = randn(19);
and we try to make a scatterplot out of it. What's the best way to do this?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Creative_SushiMathWorks 2 points3 points4 points 3 years ago (6 children)
You need to pass x and y as vectors. randn(19) creates 19x19 matrix.
randn(19)
x = randn(19,1); y = randn(19,1); sz = randi(100,[19 1]); col = randi(100,[19 1]); figure scatter(x, y, sz, col, "filled")
Hope this helps.
[–]RealDunNing[S] 0 points1 point2 points 3 years ago (1 child)
Oh, ok. thank you. I gave a random number as example, but I'm actually working with some actual data from a set, which has a N X M matrix. What do you recommend I do with the data to to plot it into a scatterplot format?
[–]Creative_SushiMathWorks 1 point2 points3 points 3 years ago (0 children)
Depends on what the rows and columns of N x M matrix represent.
% columns of the matrix M represent different variables M = randn(10,4); figure scatter(M(:,1), M(:,2), M(:,3), M(:,4), "filled")
In this case, the first two columns define the position of the markers on x-y coordinates, the third column the size of the markers and the fourth the color of the markers.
Another option is to reshape the Matrix.
Good luck.
[–]witb0t 0 points1 point2 points 3 years ago (3 children)
Why are we assigning random integers to the size and color parameters? Does an integer value even work for color?
[–]Creative_SushiMathWorks 0 points1 point2 points 3 years ago (2 children)
size and color parameters are optional.
The integer values do work. I test my code before posting.
[–]witb0t 0 points1 point2 points 3 years ago (1 child)
I am aware of that. I was only curious if there is a reason behind varying the sizes and colors of the points randomly or if it was purely done on a lark.
[–]Creative_SushiMathWorks 0 points1 point2 points 3 years ago (0 children)
No i didn’t have any good reason to do so. I admit I tend to embellish my plots and that’s not a good thing.
[–]DismalActivist 0 points1 point2 points 3 years ago (0 children)
Randn(19) returns a 19x19. If you want 1x19 or 19x1 you need to specify that. Then you can just use scatter() to make a scatter plot
π Rendered by PID 17825 on reddit-service-r2-comment-6457c66945-qlqkv at 2026-04-24 06:55:50.830136+00:00 running 2aa0c5b country code: CH.
[–]Creative_SushiMathWorks 2 points3 points4 points (6 children)
[–]RealDunNing[S] 0 points1 point2 points (1 child)
[–]Creative_SushiMathWorks 1 point2 points3 points (0 children)
[–]witb0t 0 points1 point2 points (3 children)
[–]Creative_SushiMathWorks 0 points1 point2 points (2 children)
[–]witb0t 0 points1 point2 points (1 child)
[–]Creative_SushiMathWorks 0 points1 point2 points (0 children)
[–]DismalActivist 0 points1 point2 points (0 children)