Index in position 1 is invalid. Array indices must be positive integers or logical values.

2 views (last 30 days)
Hello,
I have tried various combinations of integers and no matter what I seem to do my code won't work.
inkvar=length(changeink)*var(rat_ink(changeink));
I have tried several different combinations including but not limited too:
inkvar=length(changeink)*var(rat_ink(changeink,1),1));
ink_variance=length(changeink)*var(rat_ink(changeink(1,1)*1,2));
I have even tried changing the names of my variables, nothing is working! I don't know what else to do!
changeink is 10x1 and rat_ink is 10x2
  3 Comments
MacKenzie King
MacKenzie King on 30 Sep 2020
There are no negative integers in changeink:
79.7000000000000
72.8000000000000
67.0000000000000
68.8000000000000
65.5000000000000
70.3000000000000
77.7000000000000
88.4000000000000
76.8000000000000
72
unique(mod(changeink,1))
ans =
0
0.3000
0.4000
0.5000
0.7000
0.7000
0.8000
0.8000
1.0000
min(changeink)
ans =
65.5000
max(changeink)
ans =
88.4000

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 30 Sep 2020
Edited: Cris LaPierre on 30 Sep 2020
Your values are not integers. For example, what value should rat_ink(79.7,1) return? Valid indices are 1, 2, 3, etc.
  4 Comments
Cris LaPierre
Cris LaPierre on 30 Sep 2020
You use indices inside indices. I suspect the same thing is going on with rat_ink.
Try the following:
rat_ink(round(changeink),1),1)
var(rat_ink(round(changeink),1),1))
var(round(rat_ink(round(changeink),1)),1))

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!