MATLAB: Error using ==> horzcat CAT arguments dimensions are not consistent.

feature vectorhorizontal concatenationMATLAB

I want to find feature vectors.. for that i executed the following code
clear all; close all; clc;
%%Calculating mean of im1
subplot(1, 2, 1);
imshow(grayImage, []); title('Original Grayscale Image');
% Let's get its histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(1, 2, 2); bar(pixelCount); title('Histogram of original image');
xlim([0 grayLevels(end)]); % Scale x axis manually.
yRange = ylim; % Calculate the mean gray level
meanGL = sum(pixelCount .* grayLevels) / sum(pixelCount);
%%Calculating standard deviation
%%Calculating Skewness
%%Calculating RMS
%%Calculating median absolute
%%Contruct a feature vector
fv1=[ meanGL, st_d1, sk1, rms1, md1];
and i get that concatenation error .. the size of the variables displayed in the output screen are
ans =
1 1
ans =
1 512 3
ans =
1 512 3
ans =
1 512 3
ans =
1 512 3
??? Error using ==> horzcat
CAT arguments dimensions are not consistent.
Error in ==> fvector at 64
fv1=[ meanGL, st_d1, sk1, rms1, md1];
i am new to matlab and so dont know how to fix it.. if possible any solutions..

Best Answer

  • Since you say you're trying to construct a feature vector from the expression
    fv1=[ meanGL, st_d1, sk1, rms1, md1];
    but of the five only the first,
    meanGL = sum(pixelCount .* grayLevels) / sum(pixelCount);
    isn't a higher dimension than single, I presume what you intended to write for
    %%Calculating standard deviation
    and the remaining would have been
    which will return the std dev of the entire image array im1 whereas the default behavior of std in Matlab is to operate on the planes hence return the 1x512x3 size. See
    doc std
    for further description/details. The (:) notation casts the array into a vector so the operation is then done on that one column and the result is then the desired single value for the entire image.
    Same logic/fix for the rest.
  • Related Question