why do I get "Array indices must be positive integers or logical values"

D = diabetesdata;
Dm = mean (D);
Dm = 3.8451 120.8945 69.1055 20.5365 79.7995 31.9926 0.4719 33.2409 0.3490
Dsm = D - Dm
Dsm =
0.1549 20.1055 4.8945 -20.5365 -79.7995 -4.3926 -0.2279 6.7591 -0.3490
3.1549 73.1055 -1.1055 7.4635 -79.7995 3.9074 0.2731 7.7591 0.6510
4.1549 60.1055 -1.1055 15.4635 415.2005 -1.8926 0.1431 26.7591 0.6510
-2.8451 7.1055 28.8945 20.4635 -21.7995 0.0074 0.8491 -0.2409 0.6510
4.1549 -11.8945 6.8945 18.4635 34.2005 -4.0926 0.1681 -2.2409 0.6510
1.1549 18.1055 10.8945 14.4635 80.2005 -0.3926 -0.1109 -8.2409 0.6510
-0.8451 -9.8945 -7.1055 -20.5365 -79.7995 -9.3926 -0.3299 -12.2409 -0.3490
5.1549 31.1055 8.8945 13.4635 91.2005 2.2074 0.4211 -0.2409 0.6510
3.1549 57.1055 14.8945 -20.5365 -79.7995 7.9074 -0.1409 7.7591 0.6510
-2.8451 9.1055 0.8945 -7.5365 25.2005 -6.0926 0.0001 -11.2409 -0.3490
-2.8451 -25.8945 4.8945 0.4635 -6.7995 -6.0926 0.2011 2.7591 -0.3490
.....
Dstd = std(D)
Dstd = 3.3696 31.9726 19.3558 15.9522 115.2440 7.8842 0.3313 11.7602 0.4770
Dnorm = Dsm./Dstd(D)
Array indices must be positive integers or logical values.
why am i getting this when its always worked before?

 Accepted Answer

Most probably you mean
Dnorm = Dsm./Dstd
instead of
Dnorm = Dsm./Dstd(D)

5 Comments

THE SIZE OF D IS LARGER THAN DSTD, AND Dstd(D) IS INCORRECT
THE SIZE OF D IS LARGER THAN DSTD
It's enough that the number of columns of D and Dstd are the same.
A = rand(3,6)
A = 3×6
0.9177 0.9634 0.3477 0.4052 0.2695 0.2948 0.5912 0.1184 0.9285 0.9043 0.7753 0.5850 0.3678 0.9762 0.9808 0.1172 0.2459 0.3344
b = rand(1,6)
b = 1×6
0.6558 0.8259 0.9733 0.3385 0.3217 0.8282
Abyb = A./b
Abyb = 3×6
1.3994 1.1666 0.3572 1.1973 0.8377 0.3559 0.9015 0.1434 0.9540 2.6718 2.4103 0.7064 0.5609 1.1820 1.0077 0.3462 0.7644 0.4038
Perhaps you need:
Dstd = std(D(:))
or
Dstd = std(D, "all")
I don't think so. Mean and Standard deviation are taken columnwise for the matrix D. Finally, D is normalized to Dnorm. The only problem is the use of
Dnorm = Dsm./Dstd(D)
instead of
Dnorm = Dsm./Dstd
thank you it was that which was the propblem

Sign in to comment.

More Answers (2)

Dstd(D) is requesting to index the vector Dstd by the array D
Remember MATLAB has absolutely no implied multiplication.
The only implied operations that I can think of at the moment are:
  • the name of a function that is not in quotes or comments, and is not proceeded by @ or ? and is not followed by (, is treated as an implicit call to the function as if () had been coded after the name
  • inside [] and {} then space is horizontal concatenation
  • inside [] and {} then end of line is vertical concatenation
  • in the symbolic toolbox, inside piecewise() calls, A RELATION B RELATION C is sometimes treated as A RELATION B & B RELATION C

Community Treasure Hunt

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

Start Hunting!