Rectangular Function implementation in Matlab

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 20 de Mzo. de 2013
Editada: Azzi Abdelmalek el 20 de Mzo. de 2013
rect=@(x,a) ones(1,numel(x)).*(abs(x)<a/2) % a is the width of the pulse
x=-10:0.001:10
y=rect(x,2)
plot(x,y)

6 comentarios

Rohan Repale
Rohan Repale el 25 de Mzo. de 2013
Thank you very much.
also do you know, if rect function is related to the rectwin (rectangular window) function present in matlab?
Azzi Abdelmalek
Azzi Abdelmalek el 25 de Mzo. de 2013
I am not sure to understand your question, the above rect function is not related to rectwin.
Rohan Repale
Rohan Repale el 25 de Mzo. de 2013
Got it, thankyou.
alternatively, can I use rectpulse command available in matlab to do what you have done?
Azzi Abdelmalek
Azzi Abdelmalek el 25 de Mzo. de 2013
Editada: Azzi Abdelmalek el 25 de Mzo. de 2013
You can adapt square function
Khushi Bhatti
Khushi Bhatti el 9 de Sept. de 2018
can someone please tell me how can i use a rectangular function or any function to visualize outliers in my data? i find the outliers in my data but i dnt know how to visualize them using a graph or plot.
Vamshidhar Reddy
Vamshidhar Reddy el 15 de Nov. de 2022
rectangular function do require symbolic toolbox

Iniciar sesión para comentar.

Más respuestas (2)

Johan Rincon Botia
Johan Rincon Botia el 16 de Abr. de 2022
I did the implementation for rect function with period w
My function has 4 arguments rect (T,n,amp,xtranslation), where T is the period, n is the periods that you want to show, amp is the amplitude and xtranslation is the translation at x-axis, for example, i want to do this signal:
with any period, like T = 20s, and i wanna show this 3 times,
This is how i use the function
T = 20; %Period
amplitude = 5; %Amplitude of the signal
num = 3; %Numbers of periods that you want to show
xtranslation =-8; % Translation x-axis
[t,y] = rect(T,num,amplitude,xtranslation); %the function return the time vector and amplitud vector
plot(t,y)%use t and y to plot your rect signal
An here is the implementation of the function:
function [t,y] = rect(T_period,num,ampli,xtranslation)
t = -T_period*num:0.01:T_period*num;
y_0=0;
y_1=1;
if xtranslation>=T_period/2
num = num+round((2*xtranslation/T_period))
end
for i=-num:num
y_0=y_0 + 0.*(t>T_period/2+(T_period*(i-1)) & t<T_period*num);
y_1=y_1 + 1.*(t>T_period*(i-1) & t<T_period/2+(T_period*(i-1)));
end
y= (y_0 + y_1)
y = ampli*(y-min(y));
t = t-xtranslation;
end
And this is the result, i hope that this will be useful for you!
balakrishna nair nalivalapil
balakrishna nair nalivalapil el 5 de Feb. de 2019

0 votos

rect=@(x,a) ones(1,numel(x)).*(abs(x)<a/2) % a is the width of the pulse
x=-10:0.001:10
y=rect(x,2)
plot(x,y)

1 comentario

俊豪 杨
俊豪 杨 el 28 de Mzo. de 2021
excuse me ,could i ask y u a question?how can i use rect(x,y) in matlab?

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 20 de Mzo. de 2013

Comentada:

el 15 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by