error while using subplot

조회 수: 3 (최근 30일)
Rohit singla
Rohit singla 2017년 10월 7일
댓글: Brion Root 2020년 4월 9일
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.

채택된 답변

Walter Roberson
Walter Roberson 2017년 10월 7일
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
Rohit singla
Rohit singla 2017년 10월 7일
Thanks a lot Now its working
Brion Root
Brion Root 2020년 4월 9일
Yea wow this helped me too, even my teacher didn't know why.
Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by