# Vertcat error when concatenating images in loop

1 vue (au cours des 30 derniers jours)
Siegmund Nuyts le 29 Sep 2022
Commenté : Jan le 30 Sep 2022
I am reading around 1000 images showing progress over time. I want to concatenate them to show daily average.
However, the vertcat shows error "Dimensions of arrays being concatenated are not consistent." after 126 images.
All images are same size (1680 x 965) so I'm not really sure why the erros occurs after 126 images.
Anyone an idea why and how to resolve it?
Img = dir([path,strcat('**/S_1_*')]);
t = [];
Sav = [];
for i = 1:length(Img)
t = [t; datenum(Img(i).name(5:end-4),'yyyymmddHHMM')];
Sav = [Sav; mean(vertcat(Sro),1,'omitnan')];
end
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

Jan le 29 Sep 2022
Modifié(e) : Jan le 29 Sep 2022
vertcat(Sro) concatenates Sro with nothing. What is the purpose of this command?
Ask Matlab, what the problem is:
for i = 1:length(Img)
t = [t; datenum(Img(i).name(5:end-4),'yyyymmddHHMM')];
try
Sav = [Sav; mean(Sro, 1, 'omitnan')];
catch ME
size(Sav)
size(mean(Sro, 1, 'omitnan'))
error(ME.message)
end
end
By the way, a pre-allocation is more efficient thanletting an array grow iteratively:
Sav = zeros(numel(Img), 965);
for i = 1:numel(Img)
t = [t; datenum(Img(i).name(5:end-4),'yyyymmddHHMM')];
try
Sav(i, :) = mean(Sro, 1, 'omitnan');
catch ME
size(Sav)
size(mean(Sro, 1, 'omitnan'))
error(ME.message)
end
end
##### 2 commentairesAfficher AucuneMasquer Aucune
Siegmund Nuyts le 30 Sep 2022
Thanks for the suggestion.
The error gives: "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."
The pictures show change over time so concatenating them will show "average" change.
The x-axis will then be "time" and y-axis distance.
The outcome is exactly what I need. I just don't understand why/how it gives an error after a certain amount of pictures...?
Jan le 30 Sep 2022
@Siegmund Nuyts: Please post the complete output of the error message: In which line does Matlab stop? Which sizes are displayed? Did you understand, why the sizes of the arrays are displayed before the error message? This information will show you, why the sizes are not matching. Maybe some of the images are RGB images (3D) and others in gray scale (2D)?

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by