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),:);
回答 (1 件)
Walter Roberson
2022 年 11 月 17 日
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.
カテゴリ
ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!