Borrar filtros
Borrar filtros

How to color a specific value ?

1 visualización (últimos 30 días)
Abubakr Mursi
Abubakr Mursi el 13 de Dic. de 2022
Comentada: daniel mitchell el 20 de Dic. de 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 comentarios
Jiri Hajek
Jiri Hajek el 13 de Dic. de 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 el 13 de Dic. de 2022
Hi,
all i need to color peak and trough values with a color by utilizing (area)

Iniciar sesión para comentar.

Respuestas (1)

daniel mitchell
daniel mitchell el 13 de Dic. de 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 comentarios
daniel mitchell
daniel mitchell el 20 de Dic. de 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 el 18 de Mayo de 2023
Thanks Deeply @daniel mitchell

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by