Effacer les filtres
Effacer les filtres

How to split a matrix for different plots?

2 vues (au cours des 30 derniers jours)
sia ben
sia ben le 9 Juil 2018
Modifié(e) : Stephan le 9 Juil 2018
I have a matrix which the first column are 1 or 2 or 3 or 4 or 5 . I want to done a function and plot of datas in all rows which have in the first column same numbers. For example I habe a matrix like [ 1 23 240;2 22 100;2 44 900;1 33 800,... ]. Now I want plot a function to 1. and 4. row (f(23)& f(33))in red color and the 2. &3. row (f(22) & f (44)) with blue color. is there any solution with out loops?

Réponse acceptée

Stephan
Stephan le 9 Juil 2018
Modifié(e) : Stephan le 9 Juil 2018
Hi,
for your matrix A:
>> A = [ 1 23 240;2 22 100;2 44 900;1 33 800]
A =
1 23 240
2 22 100
2 44 900
1 33 800
to get the data splitted without for loop use:
>> A1 = [A(A(:,1)==1,2),A(A(:,1)==1,3)]
A1 =
23 240
33 800
>> A2 = [A(A(:,1)==2,2),A(A(:,1)==2,3)]
A2 =
22 100
44 900
Now you have splitted data which you can plot however you want:
>> plot(A1(:,1),A1(:,2),'r')
>> hold on
>> plot(A2(:,1),A2(:,2),'b')
which gives:
Best regards
Stephan

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by