Index exceeds the number of array elements

조회 수: 1 (최근 30일)
G. Nardi
G. Nardi 2019년 1월 16일
댓글: G. Nardi 2019년 1월 17일
I am still in school learning matlab and need some help. I have seen other ones like this but they don't go into what to do with a double.
I loaded a file that has a double 10000x2
and I am getting this error.
Index exceeds the number of array elements (2).
Error in Week2(line 14)
classTwoTrainingIndices = randomizedIndices(1:6000);
2019-01-16_18-30-31.png
2019-01-16_18-31-42.png
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 1월 17일
It is easier for us to work with code rather than with images of code.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 1월 17일
randsample() by default is selection without replacement. When you pass in an integer as the first parameter, the implication is to select from 1 to the integer. As you are passing in the same integer as the second parameter, the effect you are going to get is a permutation of the numbers from one to the integer. Since NumberOfClassOneSamples is 2, that is going to be a random permutation of [1 2]... which will give you either [1; 2] or [2; 1] as the answer.
You then try to take the first 6000 entries in that pair of numbers.
In your code each row appears to represent a sample. The number of samples in of data would then be size(ClassOne, 1) not size(ClassOne,2)
Also, classOneTrainingData should be classOne(classOneTrainingIndices, :) because you want all of the entries in the row.
  댓글 수: 1
G. Nardi
G. Nardi 2019년 1월 17일
Thanks I appreciate the explanation. It was great great help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by