I think that You not need doing this. I'm offering the following variant:
LName={'Name1','Name2','Name3'};
Dat={rand(12,1),rand(12,1),rand(12,1)};
d = [LName;Dat];
Data = struct(d{:});
d1 = cell2mat(struct2cell(Data)');
[R,P] = corrcoef(d1);
Correlation = [LName(nchoosek(1:size(R,1),2)) num2cell(nonzeros(tril(R,-1)))]
OR
R = corrcoef([Dat{:}]);
Correlation = [nchoosek(1:size(R,1),2) nonzeros(tril(R,-1))]
OR
Correlation = sparse(tril(R,-1))
ADD eg:
>> LName={'Name1','Name2','Name3' 'Name4'};
Dat={rand(12,1),rand(12,1),rand(12,1),rand(12,1)};
R = corrcoef([Dat{:}])
Correlation = [LName(nchoosek(1:size(R,1),2)) num2cell(nonzeros(tril(R,-1)))]
R =
1 0.62864 0.50105 -0.066267
0.62864 1 0.20848 -0.0042032
0.50105 0.20848 1 0.23383
-0.066267 -0.0042032 0.23383 1
Correlation =
'Name1' 'Name2' [ 0.62864]
'Name1' 'Name3' [ 0.50105]
'Name1' 'Name4' [ -0.066267]
'Name2' 'Name3' [ 0.20848]
'Name2' 'Name4' [-0.0042032]
'Name3' 'Name4' [ 0.23383]
>>
Best Answer