Why do i get this error when i run the code?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
prem kumar
le 29 Jan 2022
Commenté : prem kumar
le 29 Jan 2022
Hello there friends i tried to run this code in matlab r2021b
dn=1:1:365;
x=(360/365*(dn+284));
sdelta=23.45*(sind(x)*pi/180);
L=(0:20:80);
k=(0:0.5:24);
lamda=15*(12-k);
solar_altitude=asind(sind(sdelta)*sind(L)+cosd(sdelta)*cosd(L)*cosd(lamda));
but the system shows this error ...can anybody help me out.Thank you.
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches
the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
Error in p2 (line 43)
solar_altitude=asind(sind(sdelta)*sind(L)+cosd(sdelta)*cosd(L)*cosd(lamda));
0 commentaires
Réponse acceptée
Walter Roberson
le 29 Jan 2022
dn=1:1:365;
x=(360/365*(dn+284));
sdelta=23.45*(sind(x)*pi/180);
L=(0:20:80);
k=(0:0.5:24);
lamda=15*(12-k);
whos
solar_altitude=asind(sind(sdelta)*sind(L)+cosd(sdelta)*cosd(L)*cosd(lamda));
sdeleta is 1 x 365 so sind(sdelta) is also 1 x 365
L is 1 x 5 so sind(L) is 1 x 5
(1 x 365) * (1 x 5) is an invalid operation.
It looks to me as if you want a result that is per-latitude and per-day -- so a 2D result. For long term graphing purposes it is probably easiest to have connect all of the days for a particular latitude, so you probably want one line per latitude (ignoring the other factors for now), so you should arrange for sdelta to be a column.
5 commentaires
Walter Roberson
le 29 Jan 2022
dn = (1:1/24:365).';
x=(360/365*(dn+284));
sdelta=23.45*(sind(x)*pi/180);
L=(0:20:80);
k = mod(dn, 1) * 24;
lamda=15*(12-k);
whos
part1 = sind(sdelta)*sind(L); size(part1)
part2a = cosd(sdelta)*cosd(L); size(part2a)
part2 = part2a .* cosd(lamda); size(part2)
solar_altitude = asind(part1 + part2);
whos
plot(dn, solar_altitude); legend(string(L))
plot(dn(1:200), solar_altitude(1:200,:)); legend(string(L))
Perhaps the equations are not correct when dn is fractional ?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Polar Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!