フィルターのクリア

How to create a plot using data linked to other columns?

2 ビュー (過去 30 日間)
Austin Davis
Austin Davis 2022 年 6 月 16 日
回答済み: Siraj 2023 年 8 月 31 日
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
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

サインインしてコメントする。

回答 (1 件)

Siraj
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)
t = 5×3 table
Xdata Ydata Color _____ _____ _____ 8 1 1 9 3 3.25 1 6 5.5 10 10 7.75 6 10 10
% 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.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by