Plot 2d function not working

조회 수: 5 (최근 30일)
Patrick Bradford
Patrick Bradford 2019년 8월 10일
댓글: Star Strider 2019년 8월 10일
I guess I am having a plot issue today. I tried a matlab tutorial from mathworks, did exactly what the instructor did. Plot function errors out and doesn't plot the line of the graph. This is the second time today something hasn't plotted a line. Searched matlab function doesn't draw line and went through many examples and settings. Figured i would try something that was supposed to work and wasn't an issue with my code. https://www.youtube.com/watch?v=OHxR8iMHDWw
%% sin(alpha)= sin(delta)*sin(phi)+cos(delta)*cos(phi)(15(LST-12))
%% Which is the equation for solar pannel production in kW vs time of day.
%% should result in a squared off bell curve.
lat = 42 +17/60 %% log coordinate for Natik in degrees above equator *gamma*
dec = 23.45 %% Solar declination on june 21st
lat = lat*pi/180 %% convert lat to radians
dec = deg2rad(dec) %% convert dec to radians
t = 5.5:0.25:20 %% time of day input from 5:30 am - 8 pm
LST = t - 1 + 14.6/60 %% Converts time and applies a shift
sunangle = sin(dec)*sin(lat)+cos(dec)*cos(lat)*cosd(15*(LST-12));
plot(t,sunangle);
The first problem is I tried to control/ click to select t and sunangle, to plot using the same 2d plot method. It popped up with the plot window,but no line (expected a slightly squared bell curve). But the plot was blank and it failed to add the plot code as it should have. After manually entering the plot (t,sunangle) it failed with the fault below.
Error in Solar (line 19)
plot(t,sunangle)

채택된 답변

Star Strider
Star Strider 2019년 8월 10일
Your code works correctly for me, and produces:
after adding the axes labels:
plot(t,sunangle)
xlabel('t')
ylabel('Sun Angle')
Please post the rest of the error message:
Error in Solar (line 19)
plot(t,sunangle)
There are usually more details.
Guessing here, however it might be worthwhile to run:
which('plot', '-all')
from your Command Window or a script.
The results I get all are in some subdirectories of:
C:\Program Files\MATLAB\R2019a\toolbox\matlab\...
If you get different results (that would usually show up at the beginning of the list), that could tell you what the problem could be.

추가 답변 (1개)

Patrick Bradford
Patrick Bradford 2019년 8월 10일
Great! I ran which('plot', '-all'), and it returned some matlab files I had named various names of "plotxxxxx" .m file names. I changed those and then ran it in live editor, it was super slow but it seems to at least plot correctly.
Thanks for the help!
  댓글 수: 1
Star Strider
Star Strider 2019년 8월 10일
As always, my pleasure!

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by