Plot several lines on the same plot for the same unique category

Hello,
i have a table which consists of the following data
Category Frequency Modulus
1 5 20
1 2 23
1 8 50
1 1 13
2 5 30
2 2 33
2 8 60
2 1 24
i want to plot Frequency vs. Modulus for each unique category (here i only showed 1 and 2 but i have more than that). also as you can see, my frequency data are not in sequence (they are shuffled 5,2,8,1,...). i want to produce a graph like the shown below (here, each line represents a different category). my frequqncy range is between 1 to 20.
i tried to produce a line for only one category, however what i got is shown in the other graph, i was not able to plot it in a sequential order.

2 件のコメント

darova
darova 2020 年 3 月 4 日
Number of points in each category is the same?
Mohammad Aljarrah
Mohammad Aljarrah 2020 年 3 月 4 日
yes, for each category the number of frequnecies are the same (from 1-20Hz)

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

 採用された回答

KSSV
KSSV 2020 年 3 月 4 日
編集済み: KSSV 2020 年 3 月 4 日

0 投票

Let T be your data of size m*3.
C = T(:,1) ; % category
F = T(:,2) ; % Frequency
M = T(:,3) ; % Modulus
figure
hold on
for i = 1:length(unique(C))
Fi = F(C==i) ;
Mi = M(C==i) ;
[Fi,id] = sort(Fi) ;
Mi = Mi(id)
plot(Fi,Mi,'.-')
end

4 件のコメント

Mohammad Aljarrah
Mohammad Aljarrah 2020 年 3 月 4 日
thank you very much for your quick response. your code did solve the first problem (separating them into different categories), however my data is still not in sequential order as you can see. can you please help with this? appreciate it :)
KSSV
KSSV 2020 年 3 月 4 日
Edited the answer.
Mohammad Aljarrah
Mohammad Aljarrah 2020 年 3 月 4 日
you are awesome, thank you very much
darova
darova 2020 年 3 月 4 日
try also
C = T(:,1) ; % category
F = T(:,2) ; % Frequency
M = T(:,3) ; % Modulus
N = 4; % number of points
FF = reshape(F,N,[]);
MM = reshape(M,N,[]);
plot(FF,MM)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

リリース

R2019b

質問済み:

2020 年 3 月 4 日

コメント済み:

2020 年 3 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by