From: Dustin on
Hello,

I am finally posting this question which probably has a very brief, simple response but has given me trouble for years. The following bit of code (generalized) produces the error:

for c=0.1:0.1:1
"RUN SIMULINK MODEL"
logsout.unpack('all')
Output(c*10)=max(variable1.data);
end

After c=0.1 and c=0.2 I am returned:

??? Subscript indices must either be real positive integers or logicals.

Error in ==> Script1 at 9
Output(c*10)=max(variable1.data);

It appears to me that matlab has some precision error so it doesn't see 0.3 but something really close but not equal to that.

How do I solve this?

Thank you!
From: Steven Lord on

"Dustin " <dshively(a)exergydevelopment.com> wrote in message
news:hutjbh$cq9$1(a)fred.mathworks.com...
> Hello,
>
> I am finally posting this question which probably has a very brief, simple
> response but has given me trouble for years. The following bit of code
> (generalized) produces the error:
>
> for c=0.1:0.1:1
> "RUN SIMULINK MODEL"
> logsout.unpack('all')
> Output(c*10)=max(variable1.data);
> end
>
> After c=0.1 and c=0.2 I am returned:
>
> ??? Subscript indices must either be real positive integers or logicals.
>
> Error in ==> Script1 at 9
> Output(c*10)=max(variable1.data);
>
> It appears to me that matlab has some precision error so it doesn't see
> 0.3 but something really close but not equal to that.

See Q6.1 in the newsgroup FAQ.

> How do I solve this?

The easiest way is probably:

for tenc = 1:10
c = tenc/10;
"RUN SIMULINK MODEL"
logsout.unpack('all')
Output(tenc) = max(variable1.data);
end

but read the description in Q6.1 first.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com