The end operator must be used within an array index expression

460 ビュー (過去 30 日間)
Sharena Natasha Nor Hisham
Sharena Natasha Nor Hisham 2022 年 1 月 21 日
コメント済み: Cris LaPierre 2022 年 1 月 22 日
My output is showing "The end operator must be used within an array index expression." when I try to run this:
%15. split spectograms of background noise between the training, validation, and test sets
numTrainBkg = floor(0.85*numBkgClips);
numValidationBkg = floor(0.15*numBkgClips);
XTrain(:,:,:,end+1:end+numTrainBkg) = Xbkg(:,:,:,1:numTrainBkg);
YTrain(end+1:end+numTrainBkg) = "background";
XValidation(:,:,:,end+1:end+numValidationBkg) = Xbkg(:,:,:,numTrainBkg+1:end);
YValidation(end+1:end+numValidationBkg) = "background";
Please help me solve this..
  6 件のコメント
Sharena Natasha Nor Hisham
Sharena Natasha Nor Hisham 2022 年 1 月 22 日
but now i'm facing another issue after I tried training the network:
Error using trainNetwork (line 184)
Number of observations in X and Y disagree.
Cris LaPierre
Cris LaPierre 2022 年 1 月 22 日
Please create a new question for this as it is unrelated.

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 1 月 21 日
You cannot use end in a variable that has not yet been created. Here, you are using end in the assignment to all your variables. Since they don't exist yet, you get an error. Consider this example.
a(end)=1
The end operator must be used within an array index expression.
Perhaps you meant to do this:
numTrainBkg = floor(0.85*numBkgClips);
numValidationBkg = floor(0.15*numBkgClips);
XTrain = Xbkg(:,:,:,1:numTrainBkg);
YTrain(1:numTrainBkg) = "background";
XValidation = Xbkg(:,:,:,numTrainBkg+1:end);
YValidation(1:numValidationBkg) = "background";
I've never used it on a 4D array, but you may want to look into using cvpartition.
  1 件のコメント
Sharena Natasha Nor Hisham
Sharena Natasha Nor Hisham 2022 年 1 月 22 日
Ahh I understand it now. I tried running the command you gave. And it worked! Thank you so much

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by