Hi Sanguk,
As per my understanding, you would like to know how to fix the error -‘Dimensions of arrays being concatenated are not consistent’ in your code.
The error message suggests that the dimensions of ‘XTrain’ and ‘sentimentScoresTrain’ do not match and therefore cannot be concatenated using ‘horzcat’. ‘XTrain’ and ‘sentimentScoresTrain’ should have same number of rows before concatenating them. You can check the size of ‘XTrain’ and ‘sentimentScoreTrain’ using the ‘size’ function.
size(XTrain)
size(sentimentScores)
Alternatively, you can concatenate vertically using the ‘vertcat’ function.
XTrain = vertcat(XTrain, sentimentScoresTrain);
This will add the ‘sentimentScores’ as additional rows to the ‘XTrain’ matrix, rather than as additional columns.
For further reference, please check this MATLAB Answer:
Please refer to the following documentation for more info on
- ‘vertcat’ function: https://www.mathworks.com/help/matlab/ref/double.vertcat.html
- ‘size’ function: https://www.mathworks.com/help/matlab/ref/size.html
I hope this resolves the issue you were facing.