0
votes
for ii = 1:numel(stats);   
     m(ii) = mean(stats(ii).PixelValues);    
     s(ii) = std2(stats(ii).PixelValues);
     skewww(ii) = skewness(double(stats(ii).PixelValues));
     kurtooo(ii) = kurtosis(double(stats(ii).PixelValues));
end

Fuse_Data=horzcat(m(:),s(:),skewww(:),kurtooo(:));

Error: Error using horzcat

Dimensions of matrices being concatenated are not consistent.

I use Fuse_Data as features extracted and uses as input for NN training. But I am unable to concatenate this.

When I use the whos command to inspect the variables, these are the results:

Name        Size            Bytes  Class   

m           845x1           6760   double 
s           1x1079          8632   double      
skewww      1x1079          8632   double  
kurtooo     1x1079          8632   double              
1
As you've written, m doesn't have the same number of elements as the other variables you're trying to concatenate... I suggest you initialise your variables before the loop with m = zeros(numel(stats),1); s = zeros(...) etc, because the most likely solution is that you ran this before with a larger stats variable, and never cleared s/skeww/kurtoo. Or simply clear before you run the code.Wolfie

1 Answers

1
votes

As said Wolfie, it is likely that another part of your code is messing with your value. The general problem you are dealing with comes from the fact you didn't vectorized your calculation using a for loop. As any regular Matlab user, I encourage you to use vectorization as much as possible. Notably to avoid in the future this kind of problems linked to the size of a variable:

pixVal = [stats(:).PixelValues]
m = mean(pixVal)
s = std2(pixVal);
skewww = skewness(double(pixVal));
kurtooo = kurtosis(double(pixVal));
Fuse_Data=[m',s',skewww',kurtooo']

As you can see you no longer need to worry about the previous length of m since you redefine it (like any vectorized operation does).