Error using too much data?

I dunno why I have encountered these errors
Error using *
Inner matrix dimensions must agree.
Error in fixed_solar_panel_calc (line 82)
cos_theta(ii) = sin(delta)*sin(fai)*cos(beta)...
Error in fixed_solar_panel (line 2)
[cos_theta, Qinc, B] = fixed_solar_panel_calc (latitude, longitude,
standard_meridian);
Original codes
function [cos_theta, Qinc, solard] = fixed_solar_panel_calc (latitude, longitude, standard_meridian)
% incidence.m calculates angle of incidence
% Reference: Solar engineering of thermal processes, Duffie and Beckman
tilt_angle = 0; % [deg]
% Converting from degree to radian
beta = tilt_angle *pi /180; % rad
fai = latitude *pi /180; % rad
gamma = 0; % surface azimuth angle
solar_data=xlsread('Book1'); % read solar data from xls file
month= solar_data(:,1); % month of the year
acc_day = 0;
if month == 1
acc_day = 0;
elseif month == 2
acc_day = 31;
elseif month == 3
acc_day = 59;
elseif month == 4
acc_day = 90;
elseif month == 5
acc_day = 120;
elseif month == 6
acc_day = 151;
elseif month == 7
acc_day = 181;
elseif month == 8
acc_day = 212;
elseif month == 9
acc_day = 243;
elseif month == 10
acc_day = 273;
elseif month == 11
acc_day = 304;
elseif month == 12
acc_day = 334;
end
nday = acc_day + solar_data(:,2); % [nth day of the year]
zero_insident = (solar_data(:,9)~=0);
solard = solar_data(zero_insident,:); % non-zero insident data
[row, col] = size(solard);
cos_theta = zeros(row,1); % create variable for cos_theta with fixed matrix
for ii = 1:row
B = (nday-1)*360/365; % deg (Eq 1.4.2, pg9)
% Approximation: (1.6.1a)
% angrad = 360*(284+nday)/365 *pi/180; % rad
% delta1 = 23.45*sin(angrad) *pi/180; % rad
% More accurate: (1.6.1b)
Brad = B*pi/180; % rad
delta2 = 180/pi*(0.006918-0.399912*cos(Brad)+0.070257*sin(Brad) ...
-0.006758*cos(2*Brad)+0.000907*sin(2*Brad) ...
-0.002697*cos(3*Brad)+0.00148*sin(3*Brad))*pi/180; % rad
delta = delta2;
% standard_time from other file
solar_hour = solard(ii,3);
standard_minute = solard(ii,4);
E = 229.2*(0.000075+0.001868*cos(Brad)-0.032077*sin(Brad)...
-0.014615*cos(2*Brad)-0.04089*sin(2*Brad)); % min (1.5.3)
solar_minute = standard_minute ...
+4*(standard_meridian - longitude) + E; % min (Eq 1.5.2, pg11)
if solar_minute > 60;
solar_hour = solar_hour+ 1;
solar_minute = solar_minute - 60; % if minute >60, it is not validate
end
solar_time = solar_hour + solar_minute / 60; % hour in decimal (minor inaccuracy in converting decimal second into second again)
omega = (solar_time-12.0)*15 *pi/180; % rad (Ex 1.6.1, pg15)
cos_theta(ii) = sin(delta)*sin(fai)*cos(beta)...
-sin(delta)*cos(fai)*sin(beta)*cos(gamma)...
+cos(delta)*cos(fai)*cos(beta)*cos(omega) ...
+cos(delta)*sin(fai)*sin(beta)*cos(gamma)*cos(omega)...
+cos(delta)*sin(beta)*sin(gamma)*sin(omega);%(Eq 1.6.2, pg14)
end
F_prime = 0.149; %efficiency of solar panel
area = 65.0; % m^2
Qinc = area*F_prime*(solard(:,9).*cos_theta);
[latitude, longitude, standard_meridian] = MJIIT_data;
[cos_theta, Qinc, B] = fixed_solar_panel_calc (latitude, longitude, standard_meridian);
power = trapz(1:144,Qinc)
\\\

Answers (1)

Image Analyst
Image Analyst on 17 Aug 2016
About all I can say until then is that if you have matrix1 as r1 rows by c1 columns, and matrix2 is r2 by c2, the product = r1xc1xr2xc2. The inner dimensions are c1xr2 and you know from your first linear algebra class that c1 must equal r2 if you are to successfully multiply those two matrices by each other. Evidently you don't have that. Use the debugger to find out where and why.

3 Comments

I have done this using another raw data. This is just bigger than that. I have checked the values, they agree too.
At the command line, give the command
dbstop if error
and run your program. When it stops, show us
size(delta)
size(fai)
size(beta)
size(gamma)
size(omega)
Thank you for your help. Anyway, I have found the solution. Sometimes Matlab's debug confuses you even more.

Sign in to comment.

Categories

Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange

Tags

Asked:

on 17 Aug 2016

Commented:

on 25 Aug 2016

Community Treasure Hunt

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

Start Hunting!