How to preallocate the arrays(mat​rix1,matri​x2,matrix3​) and variables(​trapdensit​ycount,bia​s,beta1,be​ta2) in the following question

2 views (last 30 days)
%clears variables, closes windows and clears screen clear all; close all; clc;
%defining variables T= 310; % absolute temperature in Kelvin Dn=1.0; Dp=0.3; Nd=1e18; Na=1e18; epsilonn=11.8; epsilonp=11.8; ni=1.5e10;
sigma_n=1e-5; sigma_p=1e-6;
% T1=0;T2=0;T3=0;T4=0;T5=0; Vth=0.026*T/300 ; window_width=1E-6;
alpha1 = 1.0;
%creating vectors len_start=0; len_end = 99; len_num_points =100;
vec_of_lengths = linspace(len_start,len_end, len_num_points);
rad_start=1; rad_end =100 ; rad_num_points = 100;
EField_num_points =100 ;
for count = 1:length(vec_of_lengths)
vec_of_rad = linspace(rad_start,rad_end, rad_num_points); vec__of_aspect_ratios = vec_of_lengths./vec_of_rad;
V_built_in=0.7;% built-in voltage in volts
volt_start = 0; volt_end = 0.95*V_built_in; volt_num_points = 100;
vec_of_volts = linspace(volt_start, volt_end, volt_num_points); length_vec_of_volts = length(vec_of_volts);
matrix1=[];
for count2= 1:17 matrix1(:,:,count2) = zeros(length_vec_of_volts, rad_num_points); end
for count2=1:4 matrix2(:,:,:,count2) = zeros(EField_num_points, rad_num_points, length_vec_of_volts); end
for count2=1:2 matrix3(:,count2) = zeros(1, rad_num_points); end
for count2=1:length(vec_of_rad)
for count3=1:length(vec_of_volts)
Ln=vec_of_rad(count3);% Ln is the diffusion length of electrons and is set equal to the radius.
Nr=Dn/(Ln*Ln*sigma_n*Vth);
taun0 = 1/(sigma_n*Nr*Vth);
taup0 = 1/(sigma_p*Nr*Vth);
taun=taun0;
taup=taup0;
trapdensitycount3(count3,count2)=taun0;
Lp=sqrt(taup*Dp);
bias(count3,count2) = vec_of_volts(count2); % assigning bias a value from voltage vector
%call depletion region function [x1,x2,x3,x4,V_built_in] = depletionregion(Nd, Na,vec_of_rad(count2),epsilonp, epsilonn, ni,bias(count3,count2), window_width)
if(bias(count3,count2) > V_built_in ) %V_built_in(count3,count2))
break;
end %end if
%add x1 and x2 d1=x1 + x2;
%add x3 and x4 d2=x3 + x4;
% define dimensionless variables
beta1(count3,count2) = vec_of_rad(count2)/Lp;
beta2(count3,count2) = (vec_of_rad(count2) - x1)/Lp; % x1(count3,count2))/Lp; this commented part has to be used after
beta3 = alpha1*vec_of_lengths(count2);
end
end
end

Accepted Answer

Geoff Hayes
Geoff Hayes on 15 Oct 2014
Look at how you are updating Matrix1
matrix1=[];
for count2= 1:17
matrix1(:,:,count2) = zeros(length_vec_of_volts, rad_num_points);
end
The third dimension is based on count2, so must be 17. Within each matrix1(:,:,count2) we insert a zeros matrix with length_vec_of_volt rows and rad_num_points columns. So we can initialize matrix1 as
matrix1 = zeros(length_vec_of_volts, rad_num_points, 17);
The same can be done for matrix2, matrix3, and the other variables. However, given that your code only initializes the matrix1, matrix2, and matrix3 and doesn't make use of them, it isn't clear why you need to do this.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!