У меня есть ошибка в этом коде неопределенной функции или метода 'h' для входных аргументов типа 'double'. Ошибка в ==> CAC при 55, если h(iii)==1
это дает мне ошибку типа функции
Что я уже пробовал:
T=100; % simulation time no=zeros(1,T); % log for the number of accepted calls from the start to certain second (for NAJCAC) no2=zeros(1,T); % log for the number of accepted calls from the start to certain second (for AJCAC) band_av=zeros(1,6*T); % log for the avilable banwidth (for NAJCAC) band_av(1,1:6)=[5 7 5 7 5 7]; % intial value of bandwidth (for NAJCAC) h_flag=ones(1,6*T); % flag used to know if the bandwidth reserved for the hand-off calls are used (forNAJCAC) band_av2=zeros(1,6*T); % log for the avilable banwidth(for AJCAC) band_av2(1,1:6)=[5 7 5 7 5 7]; % intial value of bandwidth (for AJCAC) res_band2=zeros(1,6*T); % reserved from hand-off calls (for AJCAC) resn_band2=zeros(1,6*T); % reserved from new calls (for AJCAC) h_flag2=ones(1,6*T); % flag used to know if the bandwidth reserved for the hand-off calls are used (for AJCAC) drop=0; % counter for the droped calls (for AJCAC) block=0; % counter for the blocked calls (for AJCAC) drop_p=zeros(1,T); % log for the droped calls from the start to certain second (for AJCAC) block_p=zeros(1,T); % log for the blocked calls from the start to certain second (for AJCAC) drop2=0; % counter for the droped calls (for NAJCAC) block2=0; % counter for the blocked calls (for NAJCAC) drop2_p=zeros(1,T); % log for the droped calls fromthe start to certain second (for NAJCAC) block2_p=zeros(1,T); % log for the blocked calls fromthe start to certain second (for NAJCAC) numu=0; % number of new calls (total) numuh=0; % number of hand-off calls (total) % display the avilable bandwidth disp(['avilable bandwidth = ' num2str(band_av(1:6))]) disp(' ') % simulation time for ii=1:T % value of bandwidth for the new second if ii>=2 band_av(1,(ii-1)*6+1:ii*6)=band_av(1,(ii-2)*6+1:(ii-1)*6)+band_av(1,(ii-1)*6+1:ii*6); band_av2(1,(ii-1)*6+1:ii*6)=band_av2(1,(ii-2)*6+1:(ii-1)*6)+band_av2(1,(ii-1)*6+1:ii*6); disp(' ') disp(['avilable bandwidth (NAJCAC) = ',num2str(band_av(1,(ii-2)*6+1:(ii-1)*6))]) disp(['avilable bandwidth ( AJCAC) = ',num2str(band_av2(1,(ii-2)*6+1:(ii-1)*6))]) disp(' ') end numc=4; % number of calls (new + hand-off) disp(['calls in sec(' num2str(ii) ') = ',num2str(numc)]) % to display the number of call in the certain second for iii=1: numc:-1:1 %#ok<M3COL,BDSCA> req(iii)=2+round(2*rand(1)); % the values (random) of requested bandwidth dur(iii)=1+round(14*rand(1))+round(0.55*rand(1)); % the values (random) of call duration disp(['[' num2str(iii) '] bandwidth req = ',num2str(req(iii)) ' ,total time = ' num2str(dur(iii))]) h(iii)=round(0.67*rand(1)); % the call is new(75%) or hand-off(25%) req2(iii)=req(iii); if h(iii)==1 disp(' --hand-off call') numuh=numuh+1; else disp(' --new call') numu=numu+1; end end for iii=1:numc if h(iii)==1 for iiii=(ii-1)*6+1:ii*6 % the value of the minimmum bandwidth if iiii<=(ii-1)*6+3 m=2; elseif req(iii)<=2 m=2; else m=2; end % can the requested bandwidth be satisfied? if req(iii)<=band_av(iiii) band_av(1,iiii)=band_av(1,iiii)-req(iii); band_av(1,iiii+6*dur(iii))=req(iii); if req(iii)~=0 no(1,ii:T)=no(ii)+1; h_flag(iiii:6:iiii+6*dur(iii)-1)=0; h_flag(iiii+6*dur(iii))=1; end req(iii)=0; %#ok<sagrow> elseif rem(iiii,6)==0 drop=drop+1; drop_p(ii:end)=drop; disp(['**no bandwidth avilible (NAJCAC)**call number (' num2str(iii) ') has been rejected']) end % can the requested bandwidth be satisfied? if req2(iii)<=band_av2(iiii) band_av2(1,iiii)=band_av2(1,iiii)-req2(iii); band_av2(1,iiii+6*dur(iii))=req2(iii); if req2(iii)~=0 no2(ii:end)=no2(ii)+1; res_band2(iiii:6:iiii+6*dur(iii)-1)=req2(iii)-m+resn_band2(iiii); h_flag2(iiii:6:iiii+6*dur(iii)-1)=0; h_flag2(iiii+6*dur(iii))=1; end req2(iii)=0; %#ok<sagrow> elseif rem(iiii,6)==0 % can the requested bandwidth be satisfied after % the banwidth adaptition for the first RAT? for iiiii=(ii-1)*6+1:ii*6-3 band_av2(iiiii)=band_av2(iiiii)+res_band2(iiiii); res_band2(iiiii:6:60)=0; if req2(iii)<=band_av2(iiiii) band_av2(1,iiiii)=band_av2(1,iiiii)-req2(iii); band_av2(1,iiiii+6*dur(iii))=req2(iii); if req2(iii)~=0 res_band2(iiiii:6:iiiii+6*dur(iii),1)=req2(iii)-m+resn_band2(iiiii); h_flag2(iiii:6:iiii+6*dur(iii)-1)=0; h_flag2(iiii+6*dur(iii))=1; end req2(iii)=0; %#ok<sagrow> elseif rem(iiiii,3)==0 % can the requested bandwidth be satisfied % after the banwidth adaptition for the second RAT ? for iiiiii=ii*6-2:ii*6 band_av2(iiiiii)=band_av2(iiiiii)+res_band2(iiiiii); res_band2(iiiiii:6:60)=0; if req2(iii)<=band_av2(iiiiii) %#ok<align> band_av2(1,iiiiii)=band_av2(1,iiiiii)-req2(iii); band_av2(1,iiiiii+6*dur(iii))=req2(iii); if req2(iii)~=0 no2(ii:end)=no2(ii)+1; res_band2(iiiiii:6:iiiiii+6*dur(iii))=req2(iii)-m+resn_band2(iiiiii); h_flag2(iiii:6:iiii+6*dur(iii)-1)=0; h_flag2(iiii+6*dur(iii))=1; end req2(iii)=0; %#ok<sagrow> elseif rem(iiiiii,6)==0 drop2=drop2+1; drop2_p(ii:end)=drop2; disp(['**no bandwidth avilible (AJCAC)**call number (' num2str(iii) ') has been rejected']) end end end end end end end end for iii=1:numc if h(iii)==0 for iiii=(ii-1)*6+1:ii*6 if iiii<=(ii-1)*6+3 m=2; elseif req(iii)==2 m=2; else m=2; end if req(iii)<=band_av(iiii)-2*h_flag(iiii) band_av(iiii)=band_av(iiii)-req(iii); band_av(iiii+6*dur(iii))=req(iii); req(iii)=0; %#ok<sagrow> elseif rem(iiii,6)==0 block=block+1; block_p(ii:end)=block; disp(['**no bandwidth avilible for new call (NAJCAC)** call number (' num2str(iii) ') has been rejected']) end if req2(iii)<=band_av2(iiii)-2*h_flag2(iiii) band_av2(iiii)=band_av2(iiii)-req2(iii); band_av2(iiii+6*dur(iii))=req2(iii); if req2(iii)~=0 no2(ii:end)=no2(ii)+1; resn_band2(iiii:6:iiii+6*dur(iii))=req2(iii)-2; end req2(iii)=0; %#ok<sagrow> elseif rem(iiii,6)==0 for iiiii=(ii-1)*6+1:ii*6-3 band_av2(iiiii)=band_av2(iiiii)+resn_band2(iiiii); % bandwidth adaptation % but only using the bandwidth reseved for new calls resn_band2(iiiii:6:60)=0; if req2(iii)<=band_av2(iiiii)-2*h_flag2(iiiii) band_av2(1,iiiii)=band_av2(1,iiiii)-req2(iii); band_av2(1,iiiii+6*dur(iii))=req2(iii); if req2(iii)~=0 no2(ii:end)=no2(ii)+1; resn_band2(iiiii:6:iiiii+6*dur(iii))=req2(iii)-m; end req2(iii)=0; %#ok<sagrow> elseif rem(iiiii,3)==0 for iiiiii=ii*6-2:ii*6 band_av2(iiiiii)=band_av2(iiiiii)+resn_band2(iiiiii); resn_band2(iiiiii:6:60)=0; if req2(iii)<=band_av2(iiiiii)-2*h_flag2(iiiiii) band_av2(1,iiiiii)=band_av2(1,iiiiii)-req2(iii); band_av2(1,iiiiii+6*dur(iii))=req2(iii); if req2(iii)~=0 no2(ii:end)=no2(ii)+1; resn_band2(iiiiii:6:iiiiii+6*dur(iii))=req2(iii)-m; end req2(iii)=0; %#ok<sagrow> elseif rem(iiiiii,6)==0 block2=block2+1; block2_p(ii:end)=block2; disp(['**no bandwidth avilible for new call(AJCAC)**call number (' num2str(iii) ') has been rejected']) end end end end end end end end end % display the last state of the bandwidth disp(' ') disp(['avilable bandwidth (NAJCAC) = ' num2str(band_av(1,55:60))]) disp(['avilable bandwidth ( AJCAC) = ' num2str(band_av2(1,55:60))]) disp(' ') % calculate the total rejected calls rej=drop+block; rej2=drop2+block2; disp(' ') disp(['The total number of calls been dropped(NAJCAC)= ' num2str(rej) ' call/s']) disp(['The total number of calls been dropped (AJCAC)= ' num2str(rej2) ' call/s']) % calcuclate the probability of blocking and droping for AJCAC and NAJCAC for ii=1:1:T dp(ii)=drop_p(ii)/numuh; %#ok<sagrow> bp(ii)=block_p(ii)/numu; %#ok<sagrow> dp2(ii)=drop2_p(ii)/numuh; %#ok<sagrow> bp2(ii)=block2_p(ii)/numu; %#ok<sagrow> end % calculate the throughput for AJCAC and NAJCAC in certain second th=64*no/100;th2=64*no2/100; % calculate the throughput for AJCAC and NAJCAC from the start to a certain second for ii=T:-1:2 th(ii)=sum(th(ii:-1:1)); th2(ii)=sum(th2(ii:-1:1)); end % calculate the delay for AJCAC and NAJCAC d=th*8/12.5;d2=th2*8/12.5; % plot the figuers plot(1:4*T/10:4*T,dp(1:T/10:T),'r-*','linewidth',1.5,'MarkerSize',6),hold on plot(1:4*T/10:4*T,dp2(1:T/10:T),'g*','linewidth',1.5,'MarkerSize',6),legend('Non AdaptiveJCAC','AdaptiveJCAC','Location','NorthWest'),grid,ylabel('Hand-off dropping probability %'),xlabel('Call arrival rate"call/second" '),title(' Handoff Call Dropping ProbabilityVS Call Arrival Rate') figure plot(1:4*T/10:4*T,bp(1:T/10:T),'r*','linewidth',1.5,'MarkerSize',6),hold on plot(1:4*T/10:4*T,bp2(1:T/10:T),'g*','linewidth',1.5,'MarkerSize',6),legend('Non Adaptive JCAC','Adaptive JCAC','Location','NorthWest'),grid,ylabel('New call blocking probability %'),xlabel('Call arrival rate"call/second"'),title('New Call Blocking Probability VSCall Arrival Rate') figure plot(1:4*T/10:4*T,th(1:T/10:T),'r*','linewidth',1.5,'MarkerSize',6),hold on plot(1:4*T/10:4*T,th2(1:T/10:T),'g-*','linewidth',1.5,'MarkerSize',6),legend('NAJCAC','AJCAC','Location','NorthWest'),grid,ylabel('Throughput"byte"'),xlabel('Call arrival rate"call/second"'),title('Throughput VS Call arrival rate') figure plot(1:4*T/10:4*T,d(1:T/10:T),'r*','linewidth',1.5,'MarkerSize',6),hold on plot(1:4*T/10:4*T,d2(1:T/10:T),'g-*','linewidth',1.5,'MarkerSize',6),legend('NAJCAC','AJCAC','Location','NorthWest'),grid,ylabel('Delay "10^-^3second"'),xlabel('Call arrival rate"call/second"'),title('Delay VS Call arrival rate')
OriginalGriff
Две вещи:
1) СДЕЛАЙТЕ ОТСТУП В КОДЕ. Как бы то ни было, почти невозможно понять, что происходит, особенно когда он содержит такой код:
end end end end end end end end for iii=1:numc if h(iii)==0 for iiii=(ii-1)*6+1:ii*6 if iiii<=(ii-1)*6+3Отступы делают ваш код читабельным, а это значит, более надежным и более ремонтопригодным.
https://blogs.mathworks.com/community/2009/05/11/keep-your-code-readable-with-smart-indenting/
2) Не сваливайте на нас весь ваш код и не ждите, что мы волшебным образом узнаем, что не так: дайте нам только соответствующие фрагменты кода и скажите, В какой строке находится ошибка!
Помогите нам помочь вам!
Используйте виджет "улучшить вопрос", чтобы отредактировать свой вопрос и предоставить более подробную информацию.