Subscript indices must either be real positive integers or logicals (Random rainfall hyetograph)

1 visualización (últimos 30 días)
I am trying to create random precipitation pulses for a hydrological model. I generated sample sets for different climate but randomly sometimes it stops and shows this error massage.
Subscript indices must either be real positive integers or logicals.
Error in untitled3(line 30) tt(st(i):en(i),2)=P(i);
sample set is attached: sample.mat
The portion of code for this simulation is:
function [output]= Untitled3( sample,numSamples )
Trav = sample(:,1); % Rainfall duration pulse
Pav = sample(:,2); % Rainfall average intensity
Tbav = sample(:,3); % inter storm periods
remove_sam_rows = [];
for k= 1:numSamples
disp(sprintf('########### Simulation #: %i', k));
Fp = abs(rand(250, 1));
Fr = abs(rand (250,1));
Fb = abs(rand(250,1));
P = abs(-Pav(k)*log(1-Fp));
Tb = abs(-Tbav(k)*log(1-Fb));
Tr = abs(-Trav(k)*log(1-Fr));
Time = Tr+Tb;
for i = 2:250;
Time(i)=Time(i)+Time(i-1);
end
st = floor(Time-(Tr));
st = int32(st);
en = ceil(Time);
en = int32(en);
totalTime=6599;
tt=zeros(totalTime,2);
tt(:,1)=1:totalTime;
for i=1:size(en);
tt(st(i):en(i),2)=P(i);
end
tt=tt(1:6599,:);
end
output = tt;
Where: Fp,Fr and Fb are random numbers for precipitation intensity, duration and interstorm period to generate pulses. P, Tb and Tr is the precipitation intensity, interstorm period and duration. Pav, Tbav and Trav is climate sampleset average precipitation intensity, interstorm period and duration. Time is total duration of time. st, en is start and end time of each precipitation pulse and tt is total time.
For example if : K = 1, Pav(k) = 0.06 cm/hr , Tbav = 56 hr, and Trav(k)= 5 hr. One can create rainfall hyetograph for climate k=1.
Can someone help we with this problem?

Respuesta aceptada

Star Strider
Star Strider el 24 de Ag. de 2015
I didn’t run your code (I don’t have ‘k’), but the most likely cause is that ‘st’ or ‘en’ are negative or zero. The best way I’ve found to avoid this would be:
st = 1 + abs(floor(Time-(Tr)));
en = 1 + abs(ceil(Time));
or something similar, depending on how you want to use them. The idea is that neither variable is ever <=0.

Más respuestas (1)

Image Analyst
Image Analyst el 24 de Ag. de 2015
We can't run your code to try to duplicate the problem since you didn't supply enough values for those variables you mentioned. So, see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_fix_the_error_.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22.3F

Categorías

Más información sobre Climate Science and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by