Precision and indices must be positive integers
3 ビュー (過去 30 日間)
Hello, three questions for the following code
- If I don't use round() for timerise, timesta, timedecay, it will give a warn: Warning: Integer operands are required for colon operator when used as index. It is weird to use round, any better suggestions?
- My ouputpoint is integer from workspace, don't know why it has error: Array indices must be positive integers or logical values.（solved）
- The p value from workspace, looks wierd, some are accrated, some are not
P0 = 1000.0;
t0 = [10.0e-6; 100.0e-6; 500.0e-6];
td = t0;
ts = 1.0e-7;
timeset=[t0(1), ts, td(1)];
timerise = t(1:round(t0(1)/timestep)+1);
timesta = t(round(t0(1)/timestep+2):(round(t0(1)/timestep+2)+round(ts/timestep-1)));
ouputpoint = [1 round(t0(1)/timestep)+1, (round(t0(1)/timestep+2):(round(t0(1)/timestep+2)+ts/timestep-1)), (round(t0(1)/timestep+2)+ts/timestep), length(t)];
kr = Ppeak./t0;
pr = kr.*timer;
ps = Ppeak*ones(1,length(timest));
kd = (Ppeak-0)/(timest(end) - t);
b = -kd*t;
pd = kd*timed+b;
P=[pr ps pd];
回答 (3 件)
John D'Errico 2022 年 12 月 16 日
Why did this line gather an error?
kd = (Ppeak-0)/(times(end) - t);
The end operator must be used within an array index expression.
Did you define an array called times? I don't see one, and neither does MATLAB. In that case, what does MATLAB do? It assumes you want to use the FUNCTION named times. No variable? It must be a function.
Yes, you have a variable named time. But should MATLAB know what you want to do? Computers tend to be rather literal things. They do as they are told to do. And would you really want your computer to start to re-write your code for you? Maybe you would, I don't know. But I'd not totally trust a computer program to get something complicated right.
As far as being an integer from your workspace, is this number an integer?
X = 1 + eps
It looks fairly integer-ish. And sometimes if something likes like a duck, people believe is a duck.
X == 1
But it is not.