zeros populating most of my output vector
2 views (last 30 days)
Show older comments
I am trying to iterate over a changing variable in a vector so that I use said variable in a function. In this program I want to keep my output between 0.01 and 0.008. To achieve this I have to vary another different variable within the script using if statments. My functions are all working correctly so i am just wondering where i am going wrong in my process?
clear all
close all
clc
no_of_calls = [6 3 2 2 5 29 343 548 535 500 535 593 600 583 571 553 458 316 206 123 64 28 13]; %init no of calls
no_of_runs = 1;
no_of_channels = 46;
for i = 1:23
GOS = zeros(length(no_of_calls(13)), no_of_runs); % create GOS vector
no_of_channels
GOS(i) = part_3(no_of_calls(i), no_of_runs, no_of_channels);
while GOS(i) > 0.01
GOS(i) = part_3(no_of_calls(i), no_of_runs, no_of_channels);
no_of_channels
if GOS(i) > 0.01
no_of_channels = no_of_channels+1;
if i ~= 1
i = i - 1;
else
i = 1;
end
end
end
while GOS(i) < 0.008
GOS(i) = part_3(no_of_calls(i), no_of_runs, no_of_channels);
no_of_channels
if GOS(i) < 0.008
no_of_channels = no_of_channels-1;
if i ~= 1
i = i - 1;
else
i = 1;
end
end
end
end
5 Comments
Jan
on 10 Nov 2022
@Cormac Carr: Please use the tools to format code as code. Thanks.
What is the purpose of length(no_of_calls(13)) ? This is 1 in all cases. no_of_calls(13) is a scalar, so its length is 1.
A nicer replacement of:
if i ~= 1
i = i - 1;
else
i = 1;
end
is:
i = max(i - 1, 1);
Accepted Answer
David Hill
on 10 Nov 2022
You will start running into problems with higher no_of_calls because the no_of_channels will increase and factorial numbers will become too large.
no_of_calls = [6 3 2 2 5 29];
no_of_runs = 1;
GOS=zeros(1,length(no_of_calls));
no_of_channels=ones(size(GOS))*46;
for i = 1:length(no_of_calls)
GOS(i) = part_3(no_of_calls(i), no_of_runs, no_of_channels(i));
while GOS(i)>0.01 || GOS(i)<.008
if GOS(i)>.01
no_of_channels(i) = no_of_channels(i)+1;
else
no_of_channels(i) = no_of_channels(i)-1;
end
GOS(i) = part_3(no_of_calls(i), no_of_runs, no_of_channels(i));
end
end
GOS
no_of_channels
function E_1 = part_2(A_0,n)
r=(1:n)';
num1 = A_0.^r./factorial(r);
dnom = cumsum(num1,1);
E_1 = (num1./dnom)';
end
function GOS = part_3(no_of_calls,no_of_runs,no_of_channels)
n = no_of_channels;
call_lengthDIST = makedist('lognormal','mu',0.69,'sigma',0.44);
CallLength = random(call_lengthDIST,no_of_runs,no_of_calls);
A_0 = no_of_calls*CallLength/60;
E_1 = part_2(A_0, n);
GOS = mean(mean(E_1,2,"omitnan"));
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Variables 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!