Dimensions of arrays being concatenated are not consistent error.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
Antworten (1)
dpb
am 15 Dez. 2018
Bearbeitet: dpb
am 15 Dez. 2018
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 Kommentare
Siehe auch
Kategorien
Mehr zu Numeric Types finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!