Matlab Legend Function dose not work at all
이전 댓글 표시
I am simply trying to make legends on a graph with multiple traces on a single graph which should be easy with the 'legend' function.
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)
hold on
y2 = cos(2*x);
plot(x,y2)
legend('legend1','legend2')
When I run the code above I get error message "Index in position 1 exceeds array bounds (must not exceed 1)." on the line for the legend I am using version MatlabR2021a if that helps
채택된 답변
추가 답변 (1개)
Voss
2024년 4월 3일
You have a variable called legend in your workspace interfering with you calling the legend function.
Run
clear legend
to clear that variable and then run your code again.
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
