Borrar filtros
Borrar filtros

Error in Code for Lighting: "Index in position 1 is invalid. Array indices must be positive integers or logical values."

3 visualizaciones (últimos 30 días)
I am using this old code produced for EWB to calculate the lighting needs inside of a classroom. I am not proficient enough in Matlab to figure out what is going wrong. It specifically doesn't like the barlight variable, I have tried different things but it does not like modificaitons. Please let me know your suggestions.
%MATLAB Code for Light Intensity Calculation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLEANUP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear
%clc
close all
set(0, 'DefaultAxesFontName', 'Times New Roman' )
set(0, 'DefaultAxesFontSize', 11 )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Building dimensions
h= 9; % [ft] Distance floor to ceiling
L=22.87; % [ft] Length associated with x dimension
W=15.81; % [ft] Length associated with y dimension
s=2.5; % [ft] Height of desk
res=0.025; % Resolution of sample grid
% Lighting Information (Type 1 = LF, Type 2 = LED)
length_l=[1.7 1.0]; % Length of bar light
brightness=[830 960]; % lumens/light
EOL=[0.8 .85]; % Light derating factor
light_used= [.487 .649]; % Percent of light reaching desired plane
%Reference (LF): http://www.selux.us/fileadmin/us/interior/Spec_Sheet/M125/M125_F_SS-1.pdf
%Reference (LED): http://www.gelighting.com/LightingWeb/na/images/IND029-GE-Lumination-LED-Lighting-Fixtures-BL-Recessed-Spec-Sheet.pdf
num_lights = [7 6];
num_rows = [2 2];
num_cols = ceil( num_lights ./ num_rows );
last_col_rows = mod( num_lights, num_rows );
for type=1:2
if( last_col_rows(type) == 0 )
last_col_rows(type) = num_rows(type);
end
end
% Perform analysis for both LED's and Linear Fluorescents
for type=1:2
type_name = '';
if( type == 1 )
type_name = 'Linear Fluorescent';
elseif( type == 2 )
type_name = 'LED';
end
disp( ' ' );
disp( strcat( type_name, ' Analysis' ) );
disp( '-------------------------------' );
%%%%%%%%%%%%%%%%%%%%%%%%%%%% Light placement %%%%%%%%%%%%%%%%%%%%%%%%%%
col_distance = L /num_cols(type);
col_distance_adjust = col_distance/2 * (1 - last_col_rows(type)/num_rows(type) );
row_distance = ( W - (num_rows(type) * length_l(type) ) )/num_rows(type);
row_distance_last_col = ( W - (last_col_rows(type) * length_l(type) ) )/last_col_rows(type);
x_coord = col_distance/2:col_distance:(L-col_distance/2);
x_coord = x_coord + col_distance_adjust;
y_coord = row_distance/2:row_distance+length_l(type):(W-row_distance/2);
y_coord_last_col = row_distance_last_col/2:row_distance_last_col+length_l(type):(W- row_distance_last_col/2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%% Calculations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
z=h-s; %[ft] vertical distance from lights to desk
% Formatting vectors
X=0:res:L; % Vector of x steps
Y=0:res:W; % Vector of y steps
LY=length(Y); % Y vector length
LX=length(X); % X vector length
Z=ones(LX,LY)*z; % Vector of z steps
% Adjust brightness by derating factor and coefficient of utilization
bright=EOL(type)*brightness(type)*light_used(type);
% Generate the light maps (sum them as you go)
lightTot= 0;
for c=1:num_cols(type)-1
for r=1:num_rows(type)
lightTot = lightTot + barlight(X,Y,Z,x_coord(c),y_coord(r),x_coord(c),y_coord(r) + length_l,res,bright);
end
end
% Last column separately to accomodate different spacing
for r=1:last_col_rows(type)
lightTot = lightTot + barlight( X,Y,Z,x_coord(num_cols(type)),y_coord_last_col(r), x_coord(num_cols(type)),y_coord_last_col(r) + length_l, res,bright);
end
% Output lighting statistics
fprintf( 'Maximum Light Intensity: %.2f\n', max( lightTot(:) ) ) ;
fprintf( 'Minimum Light Intensity: %.2f\n', min( lightTot(:) ) ) ;
fprintf( 'Average Light Intensity: %.2f\n', mean( lightTot(:) ) ) ;
fprintf( 'Light Intensity Variance: %.2f\n\n', var( lightTot(:) ) ) ;
totalmax = max( max (lightTot) );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure('Position', [100, 100, 1050, 750]);
mesh(X,Y,lightTot) %plot light intensity
axis( [0 L 0 W 0 totalmax] )
view(2); % Uncomment to get 2D overhead views
xlabel('Room Width (ft)', 'FontSize', 12)
ylabel('Room Length (ft)', 'FontSize', 12)
zlabel('Light Intensity (fc)', 'FontSize', 12)
title( sprintf( 'Light Intensity on Work Plane (%s) - Minimum = %.2f fc', type_name, min( lightTot(:) ) ), 'FontSize',13 );
handle=colorbar;
xlabel(handle, 'Light Intensity (fc)', 'FontSize', 12);
%%%%Draw and label light placement%%%%
for c=1:num_cols(type)-1
for r=1:num_rows(type)
line([x_coord(c) x_coord(c)], [y_coord(r) y_coord(r) + length_l(type)],[totalmax totalmax],'LineWidth',3) ;
text( x_coord(c),y_coord(r),totalmax, sprintf( 'Light %d-%d', r, c ) );
end
end
% Last column separately to accomodate different spacing
for r=1:last_col_rows(type)
line([x_coord(num_cols(type)) x_coord(num_cols(type))],[y_coord_last_col(r) y_coord_last_col(r) + length_l(type)],[totalmax totalmax],'LineWidth',3);
text( x_coord(num_cols(type)),y_coord_last_col(r),totalmax, sprintf( 'Light %d-%d', r, num_cols(type)));
end
end
Linear Fluorescent Analysis
-------------------------------
Unrecognized function or variable 'barlight'.
disp( ' ' );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% End %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Respuestas (1)

Image Analyst
Image Analyst el 21 de Nov. de 2023
Editada: Image Analyst el 21 de Nov. de 2023
See the FAQ for a thorough discussion:
You do this:
line([x_coord(c) x_coord(c)], [y_coord(r) y_coord(r) + length_l(type)],[totalmax totalmax],'LineWidth',3) ;
so x_coord needs to be an array. However you never assign elements of it. It's just a simple scalar like here in your for loop:
x_coord = col_distance/2:col_distance:(L-col_distance/2);
so try giving it an index:
x_coord(type) = col_distance/2:col_distance:(L-col_distance/2);
but don't use type as the name of an iterator since it's the name of a built in function type. Call it something else like k, but not "type", "i", or "j".

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by