Error using horzcat: Dimensions of matrices being concatenated are not consistent.

Hello everyone, here is the partial code that creates above error:
counter=1;
accessRow=0;
for r=1:length(m)
accessVector=m(r);
newAccessVector=cell2mat(accessVector);
accessRow=accessRow + newAccessVector;
SplitFeaturesRow{r}=cidxE(counter:accessRow)
counter=1+accessRow;
vocabsize=1:500;
freq{r}=histc(SplitFeaturesRow{r},vocabsize);
combineFreq=horzcat(freq{:});
end
Referring code above, m output= 474 X1 cell but r output = 472 . I wonder why r did not get 474 as it should follow the length of m. I think this is the reason why I got that error message. But how to correct r?

3 comentarios

Where is the end corresponding to your for ? It does not usually make sense to combine all of the existing elements of a cell array until the cell array has been fully populated after the end of the loop.
I put the end already.
Okay... but are you sure you want to do that horzcat() within the loop? Every iteration of the loop you are overwriting the complete combineFreq variable

Respuestas (1)

Try:
out = cat(1, freq{:})

1 comentario

Error using cat Dimensions of matrices being concatenated are not consistent.
Error in (line 69) combineFreq = cat(1, freq{:});

La pregunta está cerrada.

Etiquetas

Preguntada:

el 18 de En. de 2018

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by