필터 지우기
필터 지우기

How to color a specific value ?

조회 수: 1 (최근 30일)
Abubakr Mursi
Abubakr Mursi 2022년 12월 13일
댓글: daniel mitchell 2022년 12월 20일
%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
Jiri Hajek
Jiri Hajek 2022년 12월 13일
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 2022년 12월 13일
Hi,
all i need to color peak and trough values with a color by utilizing (area)

댓글을 달려면 로그인하십시오.

답변 (1개)

daniel mitchell
daniel mitchell 2022년 12월 13일
%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
daniel mitchell
daniel mitchell 2022년 12월 20일
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 2023년 5월 18일
Thanks Deeply @daniel mitchell

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by