Array indices must be positive integers or logical values.

rng(0)
shuffledIndices = randperm(height(gTruth));
idx = floor(0.8 * height(gTruth));
trainingIdx = 1:idx;
trainingDataTbl = gTruth(shuffledIndices(trainingIdx),:);
testIdx = trainingIdx(end)+1 : length(shuffledIndices);
testDataTbl = gTruth(shuffledIndices(testIdx),:);

Respuestas (1)

rng(0)
That line would have a problem if you had a variable named rng instead of function rng being called.
shuffledIndices = randperm(height(gTruth));
That line could have a problem if you have a variable named height instead of function height being called, in the circumstancd that gTruth had any values that did not happen to be positive integers.
idx = floor(0.8 * height(gTruth));
That line could have a problem if you have a variable named floor instead of function floor being called.
If height(gTruth) is 0 or 1 then the floor() would return 0, giving idx = 0 . In that case trainingIdx = 1:idx; would assign empty to trainingIdx . And if trainingIdx is empty then your later trainingIdx(end)+1 would be trainingIdx(0)+1 which would give indexing problems.

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 17 de Nov. de 2022

Respondida:

el 17 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by