Dimensions of arrays being concatenated are not consistent error.
조회 수: 3 (최근 30일)
이전 댓글 표시
How to fix this error?
Error using HelperTestKNNClassifier (line 35)
Could not concatenate the table variable 'ActualSpeaker' using VERTCAT.
Caused by:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
for idx = 1:length(Filenames)
T = featuresTest(Fidx==idx,2:end); % Rows that correspond to one file
predictedLabels = string(predict(trainedClassifier,T(:,1:15))); % Predict
totalVals = size(predictedLabels,1);
[predictedLabel, freq] = mode(categorical(predictedLabels)); % Find most frequently predicted label
match = freq/totalVals*100;
result_file.Filename = Filenames(idx);
result_file.ActualSpeaker = T.Label{1};
result_file.PredictedSpeaker = char(predictedLabel);
result_file.ConfidencePercentage = match;
result = [result; struct2table(result_file)]; %#ok
end
답변 (1개)
dpb
2018년 12월 15일
편집: dpb
2018년 12월 15일
result_file.ActualSpeaker = T.Label{1};
...
result = [result; struct2table(result_file)];
You're trying to catenate char() arrays that may not be the same length (and, in fact, aren't). This happened because you first dereference a cell string to char, then tried to build a table. Illustration of barebones problem:
>> T.Label='Label 1'; % first char label (did the {} dereference manually)
>> res=struct2table(T); % first entry into a table is ok...
>> T.Label='Label 1001'; % later on the string is longer...
>> res=[res;struct2table(T)] % and, BOOM!
Could not concatenate the table variable 'Label' using VERTCAT.
Caused by:
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
>>
The solution is to not dereference the label but leave as cell strings (or, if appropriate, convert to categorical )
result_file.ActualSpeaker = T.Label(1);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 GPU Computing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!