plotting a multiple output function

7 visualizaciones (últimos 30 días)
Moussa Ihab
Moussa Ihab el 25 de Mayo de 2020
Comentada: Moussa Ihab el 26 de Mayo de 2020
Hello!
I am quite new at Matlab
I have tried to plot a multiple output function but all i got is the first out put.
this is the code :
function [h, H] = myrct (t,f,beta)
% In optical communication systems, different linear pulse-shaping filters
% are used to generate continuous-time transmit signals. We can define
% these filters either through their impulse response hp(t) or their
% frequency response Hp( f )=F{hp(t)}, where F{ } stands for the Fourier
% transform.
% rct: Raised-cosine time domain (RCT-Filter)
% Time Domain
h = (1 + cos((pi./beta).*(abs(t)-(1-beta)/2)))/2;
h(abs(t)>(1+beta)/2) = 0;
h(abs(t)<(1-beta)/2) = 1;
h(abs(t)==1/2) = 1/2;
% Frequency Domain
% H = fftshift(fft(h),1);
H = sinc(f).*cos(pi.*beta.*f)./(1-(2*beta.*f).^2);
H(f == -0.5/beta) = sinc(1/(2*beta))*pi/4 ;
H(f == +0.5/beta) = sinc(1/(2*beta))*pi/4;
end
I tried to use :
figure
plot(myrct(t,f,beta))
hold on
It doesn't work and it plots only the first output 'h'.
i tried also
figure
plot(H)
hold on
but I got a msg of Unrecognized function or variable 'h'.
Here are the constants:
l=randi(50,1)
N=randi(50,1)
t=(-l*N/2:l*N/2-1)'/N;
f=(-l*N/2:l*N/2-1)'/l;
beta=rand(1)
please help me with this

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 25 de Mayo de 2020
Moussa - rather than trying to calculate and plot the results of the myrct in one like like
plot(myrct(t,f,beta))
split this into two lines to make clear what the outputs are for myrct. Try
[h, H] = myrct(t,f,beta);
figure;
plot(h);
hold on;
plot(H);
or however you want to do this. If I recall correctly, if you just call the function without specifying the output parameters like
[h, H] = myrct(t,f,beta);
then myrct(t,f,beta) will just return the first output parameter, the h. Note also that you need to explicilty set the output parameters in order to be able to reference them. We do that with the above line of code. When you don't do that and then try to reference (later) h or H you will get an error like you mentioned above Unrecognized function or variable 'h'.

Más respuestas (0)

Categorías

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

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by