MATLAB: Help me with for loop.

for loop

Hi,
I need help, I have 2 patches and I need to get the similarity between these patches and put the similarity values in matrix A.
So, matrix A will be 2*2.
I want for loop to shorten my code.
My code is
A = zeros ([2 2]);
x1 = double(patches {1,1});
x2 = double(patches {2,1});
% Patch #1
x = double (reshape(x1,[],1));
y = double (reshape(x1,[],1));
Cs = getCosineSimilarity(x,y);
A(1,1) = Cs;
x = double (reshape(x1,[],1));
y = double (reshape(x2,[],1));
Cs = getCosineSimilarity(x,y);
A(1,2) = Cs;
% Patch #2
x = double (reshape(x2,[],1));
y = double (reshape(x1,[],1));
Cs = getCosineSimilarity(x,y);
A(2,1) = Cs;
x = double (reshape(x2,[],1));
y = double (reshape(x2,[],1));
Cs = getCosineSimilarity(x,y);
A(2,2) = Cs;

Best Answer

Code can be simplified to this
A = zeros ([2 2]);
x(:,1) = double(patches{1,1}(:));
x(:,2) = double(patches{2,1}(:));
for i=1:2
for j=1:2
A(i, j) = getCosineSimilarity(x(:,i),x(:,j));
end
end
For general case which consider all patches
patches = patches(:);
patches = cellfun(@(x) {double(x(:))}, patches);
A = zeros (numel(patches));
for i=1:numel(patches)
for j=1:numel(patches)
A(i, j) = getCosineSimilarity(patches{i},patches{j});
end
end