how to use array indices in not logical form

조회 수: 3 (최근 30일)
arash rad
arash rad 2022년 7월 25일
댓글: Walter Roberson 2022년 7월 25일
Hi
I am working on a project and I have the equation below and when I use for loops because my T is a float Number something like 0.15 I get an error that I should use positive or logical numbers how sholud I fix that ??
thank you
  댓글 수: 3
arash rad
arash rad 2022년 7월 25일
편집: Matt J 2022년 7월 25일
%-- Extract some data
arrival=xlsread('tripinfo.xlsx','G:G');
depart_time=xlsread('tripinfo.xlsx','B:B');
speed_m = xlsread('loop.xlsx','G:G');
N_veh = xlsread('loop.xlsx','J:J');
Nt = length(speed_m)/2;
speed = zeros(Nt,1);
vehicle_number = zeros(Nt,1);
qu = zeros(Nt,1);
%-- Here we calculate number of vehicles that we need for calcualtion
%parameters
for k = 1:Nt;
speed(k,1) = [speed_m((2*k)-1) + speed_m(2*k)]/2;
vehicle_number(k,1) = [N_veh((2*k)-1) + N_veh(2*k)];
qu(k,:) = vehicle_number(k,1);
end
speed;
vehicle_number;
qu = qu';
%-- first we want to extract data from sumo in every 10 minutes.in step one
%we want to calculate how many cars are in the intersection in specific
%intersection
figure;
bar(qu)
title("Upstream Flow")
%% calculate parametrs
delta_x = 500 - 70 ;
T = zeros(Nt,1);
for i =1:length(qu)
tm(i,:) = ((1/qu(i))*(delta_x/speed(i)));
T(i) = delta_x/(speed(i)); %lag time
end
tm ;
beta = 0.8;
alpha = 0.5;
ta = beta*tm; %lag time
Ftu_den = 1+(alpha*ta);
Ftu = 1./Ftu_den;
%% Arriving flow distribution
qd = zeros(Nt,1);
for j =ta:ta+length(qu))
qd(:,j) = ((((1-Ftu).^(j-ta(j)))).*Ftu)*qu(j)
end
Walter Roberson
Walter Roberson 2022년 7월 25일
tm(i,:) = ((1/qu(i))*(delta_x/speed(i)));
tm is a vector or perhaps a 2D array. Not scalar.
beta = 0.8;
alpha = 0.5;
ta = beta*tm; %lag time
ta is a constant multiple times tm, and tm is non-scalar so ta is non-scalar.
for j =ta:ta+length(qu))
What does it mean to have a for loop whose lower bound is an array ?
qd(:,j) = ((((1-Ftu).^(j-ta(j)))).*Ftu)*qu(j)
Suppose the for loop somehow managed to assign the full array ta to j . Then you use ta(j) so you would be indexing ta at the values of ta . Are you sure that is wise?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2022년 7월 25일
syms F_cyc_k i q_up T t
assume(0 < F_cyc_k & F_cyc_k < 1)
assume(T > 0)
q_down = symsum( ((1-F_cyc_k)^(i-T) * F_cyc_k)*q_up*(t-i), i, T, inf)
q_down = 
The limit would be different if might be outside the range 0 to 1 exclusive, or if T might be negative.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by