フィルターのクリア

HOW TO PLOT DATA BASED ON DATA IN ANOTHER COLUMN

12 ビュー (過去 30 日間)
diala yazbeck
diala yazbeck 2021 年 2 月 21 日
コメント済み: Cris LaPierre 2021 年 2 月 23 日
HI!
i have 5 coloumns of data wiht over 1000 entries.
i want to plot column 4 and 5 against each other (x and y respectively) based on the value in column 1.
for example.
for length of coloumns
for value in column 1 = 1
plot corresponsponding column 4 and 5 values
for value column 1 = 2
plot corresponsponding column 4 and 5 vlaues
etc
end
i want to plot the conditions in a different colour as well.
please help :)

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 2 月 22 日
What type of plot do you want? If a scatter plot, use gscatter.
% Create data
A=[randi(2,100,1),rand(100,1),rand(100,1)];
A=sortrows(A,2);
ind = A(:,1)==1;
% Create grouped scatter plot
gscatter(A(:,2),A(:,3),A(:,1))
If you prefer a line plot instead, use logical indexing to select your groups. Here's a simple example assuming two groups in column 1.
figure
% Use logical indexing to identify one group
ind = A(:,1)==1;
% Use 'not ==1' syntax to plot second group
plot(A(ind,2),A(ind,3),A(~ind,2),A(~ind,3))
  7 件のコメント
diala yazbeck
diala yazbeck 2021 年 2 月 23 日
ignore the data legend!
Cris LaPierre
Cris LaPierre 2021 年 2 月 23 日
What isn't working? gscatter should work fine for any similarly formatted data. The only limiting input right now is the specified colors. Remove the 'rb' input, and see if your code runs for any data file. If it does, then we can worry about specifying color.

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

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by