ERROR message when running code
조회 수: 2 (최근 30일)
이전 댓글 표시
The following command only plots the first subplot and gives the ERROR message:
Error in subplot (line 8)
subplot(3,1,1);
and this is the code below:
clear all
clc
x = 0 : pi/150 : 2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
subplot(3,1,1);
plot(x, y1, 'r')
subplot(3,1,2);
plot(x, y2, 'g')
subplot(3,1,3);
plot(x, y3, 'b')
grid off
xlabel('Time (sec)');
ylabel('Amp (v)');
title('Signal xt');
legend('y1', 'y2', 'y3');
댓글 수: 2
Adam Danz
2019년 4월 16일
The code works fine for me, without error. The only problem I see is the legend() does not specify object handles and therefore only shows one of the three lines.
Please copy-paste the entire error message and tell us what version of matlab you're running. Run 'ver' (without quotes).
채택된 답변
Star Strider
2019년 4월 16일
편집: Star Strider
2019년 4월 19일
Your code plots all three variables. Note that they only differ by phase, so the easiest way to detect the difference is where they begin at ‘x=0’.
The error is not an error. It is a Warning, because you are plotting one variable and the legend specifies three variables. You either need to use a separate legend call in every subplot, or instead use the title function with each subplot.
EDIT —
‘Attempt to execute SCRIPT subplot as a function:’
You have a script that you named ‘subplot’. This is called ‘overshadowing’ a MATLAB function. Please do not do that!
The solution is to re-name your script to something that does not have the same name as a MATLAB function. For example rename it to ‘mySubplot.m’ or something similar that makes sense in the context of your code.
댓글 수: 1
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!