How to color a specific value ?

9 Ansichten (letzte 30 Tage)
Abubakr Mursi
Abubakr Mursi am 13 Dez. 2022
Kommentiert: daniel mitchell am 20 Dez. 2022
%Sine and cos sequence in MATLAB
close all;
clc;
n=-20:20;
x_n=sin(pi/2-2*pi*0.1*n);
plot(n,x_n);
xlabel('Time sample');
ylabel('Amplitude');
hold on;
x2_n=cos(2*pi*0.1*n);
plot(n,x_n);
xlabel('Time sample');
ylabel('Amplitude');
very good moring to all of you.
can anyone help me I want to color positive value in a red and negative value in blue??
  2 Kommentare
Jiri Hajek
Jiri Hajek am 13 Dez. 2022
Hi, see this discussion with examples: https://stackoverflow.com/questions/31685078/change-color-of-2d-plot-line-depending-on-3rd-value
Abubakr Mursi
Abubakr Mursi am 13 Dez. 2022
Hi,
all i need to color peak and trough values with a color by utilizing (area)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

daniel mitchell
daniel mitchell am 13 Dez. 2022
%Sine and cos sequence in MATLAB
close all;
clc;
n=-20:20;
f = 0.1;
n0 = 1/(4*f)-4/(2*f):1/(2*f):1/(4*f)+3/(2*f);
ns = sort([n n0]);
x_n=sin(pi/2-2*pi*0.1*ns);
x_n = round(x_n,3);
x_n_neg = nan(size(x_n)); x_n_neg(x_n<=0) = x_n(x_n<=0);
x_n_pos = nan(size(x_n)); x_n_pos(x_n>=0) = x_n(x_n>=0);
figure; hold on;
plot(ns,x_n_neg,'r');
plot(ns,x_n_pos,'b');
xlabel('Time sample');
ylabel('Amplitude');
  3 Kommentare
daniel mitchell
daniel mitchell am 20 Dez. 2022
just noticced it now well simply replace plot with area..
%Sine and cos sequence in MATLAB
close all;
clc;
n=-20:20;
f = 0.1;
n0 = 1/(4*f)-4/(2*f):1/(2*f):1/(4*f)+3/(2*f);
ns = sort([n n0]);
x_n=sin(pi/2-2*pi*0.1*ns);
x_n = round(x_n,3);
x_n_neg = nan(size(x_n)); x_n_neg(x_n<=0) = x_n(x_n<=0);
x_n_pos = nan(size(x_n)); x_n_pos(x_n>=0) = x_n(x_n>=0);
figure; hold on;
area(ns,x_n_neg);
area(ns,x_n_pos);
xlabel('Time sample');
ylabel('Amplitude');
Abubakr Mursi
Abubakr Mursi am 18 Mai 2023
Thanks Deeply @daniel mitchell

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by