Plot 2d function not working

6 views (last 30 days)
Patrick Bradford
Patrick Bradford on 10 Aug 2019
Commented: Star Strider on 10 Aug 2019
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)

Accepted Answer

Star Strider
Star Strider on 10 Aug 2019
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.

More Answers (1)

Patrick Bradford
Patrick Bradford on 10 Aug 2019
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!

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!