I am trying to shade two area (Area A and B in the image below) under a curve with two different colours. Please help me out. mat file is attached.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Biswarup Dutta
il 15 Mar 2017
Commentato: Biswarup Dutta
il 16 Mar 2017
As per my code, whole curve area is becoming green. I am trying to mark Area-A as green & Area-B as red. Code-
clc
a=importdata('robin roy.mat');
b=a.data;
x=b(22000:25830,1);
plot(x);
id = 1:length(x) ;
x(x<0)=[];
findpeaks(x);
findpeaks(x,'MinPeakHeight',1.15);
Area1 = trapz(id(1:447),x(1:447)) ;
Area2 = trapz(id(447:1815),x(447:1815)) ;
hold on
ha1 = area(x(x<=447),'FaceColor','g');
ha2 = area([447 x0], [y(x == 447) 0], 'FaceColor','r');
hold off
A1str = sprintf('Area 1 = %6.3f', Area1);
A2str = sprintf('Area 2 = %6.3f', Area2);
legend([ha1 ha2], A1str, A2str)
Risposta accettata
KSSV
il 16 Mar 2017
a=importdata('robin roy.mat');
b=a.data;
x=b(22000:25830,1);
plot(x);
id = 1:length(x) ;
x(x<0)=[];
findpeaks(x);
findpeaks(x,'MinPeakHeight',1.15);
Area1 = trapz(id(1:447),x(1:447)) ;
Area2 = trapz(id(447:1815),x(447:1815)) ;
hold on
% ha1 = area(x(x<=447),'FaceColor','g');
% ha2 = area([447 x], [y(x == 447) 0], 'FaceColor','r');
ha1 = area(id(1:447),x(1:447),'FaceColor','g') ;
ha2 = area(id(447:1815),x(447:1815),'FaceColor','r') ;
hold off
A1str = sprintf('Area 1 = %6.3f', Area1);
A2str = sprintf('Area 2 = %6.3f', Area2);
legend([ha1 ha2], A1str, A2str)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!