Error using horzcat. CAT arguments dimensions are not consistent.
Show older comments
Dear all,
Using the next function, I get the error mentioned:
function [Y]=descriptiveStats( X )
M={};
N=[];
M={'mean','sem','numel','std','var','min','max'}.';
[mean,sem,numel,std,var,min,max]=grpstats(X,[],{'mean','sem','numel','std','var','min','max'});
N=[mean,sem,numel,std,var,min,max].';
Y=[M,N];
xlswrite('df.xlsx',Y)
end
The results displayed in the command window look like this:
>> dFStats = descriptiveStats(decodeFemale);
size(M)
7 1
size(N)
7 1
M
'mean'
'sem'
'numel'
'std'
'var'
'min'
'max'
N
1.7802
0.0935
186.0000
1.2749
1.6254
0
4.7137
Error using horzcat
CAT arguments dimensions are not consistent.
Error in descriptiveStats (line 20)
Y=[M,N];
However, if I use an additional argument gname that displays a character I don't get the aforementioned error:
function [Y]=descriptiveStats( X )
M={};
N=[];
M={'mean','sem','numel','gname','std','var','min','max'}.';
[mean,sem,numel,gname,std,var,min,max]=grpstats(X,[],{'mean','sem','numel','gname','std','var','min','max'});
N=[mean,sem,numel,gname,std,var,min,max].';
Y=[M,N];
xlswrite('df.xlsx',Y)
end
And this are the results printed in the command window:
>> dFStats = descriptiveStats(decodeFemale);
size(M)
8 1
size(N)
8 1
M
'mean'
'sem'
'numel'
'gname'
'std'
'var'
'min'
'max'
N
[1.7802]
[0.0935]
[ 186]
'1'
[1.2749]
[1.6254]
[ 0]
[4.7137]
It's not a big deal to have to use the gname argument in order to avoid the error, but I don't understand why it is happening.
Can somebody explain what's the cause and how to fix it?
Regards,
Diego
Accepted Answer
More Answers (2)
Vishal Rane
on 5 Dec 2012
1 vote
Check the data type of N in both cases.
Ganesh K Davanagege
on 25 Nov 2016
Edited: Ganesh K Davanagege
on 25 Nov 2016
I have the same problem with horzcat. I tried num2cell. But, it is not working. Can anybody help me.
clc
clear all
filename = 'testdata.xlsx';
timeVariable=ones(1,10)
timeVariable = timeVariable'
tempVariable = 10*rand(1,10)
tempVariable = tempVariable'
% A = {'Time','Temperature'; 12,98; 13,99; 14,97};
a = horzcat(timeVariable, tempVariable);
A = {'Time','Temperature'; [timeVariable, tempVariable]};
% A = {'Time','Temperature'; a}; % I tried this also.
sheet = 1;
xlRange = 'E1';
xlswrite(filename,A,sheet,xlRange)
2 Comments
Walter Roberson
on 25 Nov 2016
A = {'Time','Temperature'; timeVariable, tempVariable};
Ganesh K Davanagege
on 26 Nov 2016
Thank you Walter Roberson..! It is working.
Categories
Find more on Resampling Techniques in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!