变量P在每个交互错误上改变大小

时间:2016-11-07 00:54:43

标签: matlab

很抱歉我只是在学习,但我试图理解为什么这行代码导致第17行出错。

  

电工出错(第17行)           P(i,j)= p * A(i)* E(i)* 0.01; %日平均总功率(2D矩阵)

clear all;
close all;
%--------------------------------------------------------
%   Vector of available area widths (a 1D array of numbers)
Wmiles  = [1:1:150;    %   width of the square area in miles  (vector or 1D array)
Wmeters = Wmiles*1609;  %   width of the square area in meters (vector or 1D array)
A  =  Wmeters*Wmeters; %   area in m^2 (vector or 1D array); note element-by-element 
                        %   vector multiplication!
%--------------------------------------------------------
%   Vector of available array efficiencies (a 1D array of numbers)
E   = [1:1:20];         %   efficiency percentage (vector or 1D array)         
%--------------------------------------------------------
%   Matrix of all available total output powers of the array (a 2D array of numbers)
p   = 270.9;                 %   average daily solar radiation in W per m^2 (scalar)
for i = 1:length(A)          %   index i corresponds to different areas A
    for j = 1:length(E)      %   index j corresponds to different efficiencies E 
        P(i,j) = p*A(i)*E(i)*0.01;   %"Causing ERROR" total average daily power (2D matrix)     
    end
end
%--------------------------------------------------------
%   "Plot" the matrix - a contour plot of all available total output powers
v     = [2 10 50 100 300 500 1000]; %   create contour plot levels in GWatts
C = contourf(P*1e-9, v);       %   create contour plot of output powers in GWatts 
colormap(summer);
clabel(C, 'FontSize', 11, 'Color', 'r'); %   be fancy (do not have to)
grid on; xlabel('Efficiency, %'); ylabel('Area size, m^2');

1 个答案:

答案 0 :(得分:0)

您需要E(j)而非E(i)才能匹配指数