How to create a plot using data linked to other columns?
6 次查看(过去 30 天)
显示 更早的评论
I apologize if this is really simple, I likely don't have the vocabulary or experience to search for it or ask it more clearly.
I've primarily worked with Rstudio in the past. There, if I have a table, I can plot data from a given column while still retaining information about it other than the title. For example, if I want to create a scatter plot of the ratio of blue fluorescence against red fluorescence in cells, I could do so, with blue on X and red on Y, and then more clearly define the points with information provided in corresponding other columns. E.g., I could color the points by cell strain, and denote the shape by replicate.
My question is: how do I do something like this in Matlab?
I have provided an example data set.
[removed incorrect code]
2 个评论
dpb
2022-6-16
I don't what that was an answer to or where you found it, but it is not MATLAB syntax.
For your question, see gscatter
Peter Perkins
2022-6-17
This also came up in one of the threads for another post:
回答(1 个)
Siraj
2023-8-31
Hii!
It is my understanding that you have a table and want to plot any one column of the table with respect to some other column of the table.
It is possible to do this. First, access the relevant data stored in the columns. This can be done in multiple ways. Refer to the following document to learn more about this.
Once we get this data, we can simply pass this data to any relevant function like plot, scatter, etc.
We can also set the properties of the scatter plot or plot, in general, using some other column of the table.
To learn about the properties of scatter plots refer to the following.
Attaching a small example to make things clearer.
rng(0);
xdata = randi([0 10], 5,1);
ydata = randi([0 10], 5,1);
colors = linspace(1,10,5)'; %this can be generated randomly also.
% creating a table. (Can read this table from a xlsx file also)
t = table(xdata,ydata,colors,'VariableNames',[ "Xdata", "Ydata", "Color"]);
display(t)
% accessing different columns of the data and plotting.
plt = scatter(t.Xdata,t.Ydata, [], t.Color, "filled", LineWidth=3);
To learn more about tables and their properties refer to the following.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!