error while using subplot

3 visualizaciones (últimos 30 días)
Rohit singla
Rohit singla el 7 de Oct. de 2017
Comentada: Brion Root el 9 de Abr. de 2020
code:
t=0:0.001:1;
set(0,'defaultlinelinewidth',2);
A=5;%Amplitude of signal
fm=input('Message frequency=');%Accepting input value
fc=input('Carrier frequency=');%Accepting input value (f2>f1)
mi=input('Modulation Index=');%Modulation Index
Sm=A*sin(2*pi*fm*t);%Message Signal
subplot(3,1,1); %Plotting frame divided in to 3 rows and this fig appear at 1st
plot(t,Sm);
xlabel('Time');
ylabel('Amplitude');
title('Message Signal');
grid on;
Sc=A*cos(2*pi*fc*t);%Carrier Signal
subplot(3,1,2);
plot(t,Sc);
xlabel('Time');
ylabel('Amplitude');
title('Carrier Signal');
grid on;
Sfm=(A+mi*Sm).*sin(2*pi*fc*t);%AM Signal, Amplitude of Carrier changes to (A+Message)
subplot(3,1,3);
plot(t,Sfm);
xlabel('Time');
ylabel('Amplitude');
title('AM Signal');
grid on;
but when i run the program,show this type of error given below:
Attempt to execute SCRIPT subplot as a function:
C:\Users\Rohit\Documents\MATLAB\subplot.m
Error in subplot (line 8)
subplot(3,1,1); %Plotting frame divided in to 3 rows and this fig appear at 1st.

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Oct. de 2017
You created a .m file named C:\Users\Rohit\Documents\MATLAB\subplot.m which is interfering with using the MATLAB subplot() function. You must either rename C:\Users\Rohit\Documents\MATLAB\subplot.m to something else, or else make sure that it later on your MATLAB path than toolbox/matlab/graph2d/subplot.p is.
I would advise you that as long as you have your own subplot.m that you are going to run into this problem over and over again. Creating your own .m named the same thing as one of the common MATLAB functions is "asking for trouble".
  2 comentarios
Rohit singla
Rohit singla el 7 de Oct. de 2017
Thanks a lot Now its working
Brion Root
Brion Root el 9 de Abr. de 2020
Yea wow this helped me too, even my teacher didn't know why.
Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by