# MATLAB: How to perform a single Matrix calculation and store result back into a vector or matrix

matrix amatrix array

Hi, Everyone
I have written a code which calculates weighted distance in a single matrix. (similar to euclidean distance). I need to know how to store my results back into a matrix or vector instead of displaying it n times.
Here is my code
///////////////////////////
i=1; j=2; for i=1:4for j=2:5      if((i~=j)&&(i<j))  d=0;           for k=1:6       sum=(data(j,k)-data(i,k))^2;       d=d+sum;            endd=(0.25*d)^(1/2)       end         end  ////////////////////  end
For example if I have a 5×6 matrix as given below
85 92 45 27 31 085 64 59 32 23 086 54 33 16 54 091 78 34 24 36 087 70 12 28 10 0
my results are displayed as
d =16.3478d =23.6590d =9.8362d =22.4666d =22.3271d =16.5076d =24.6678d =15.7321d =26.3534d =17.7200
But I would like to store as
d=[ 16.3478; 23.6590; 9.8362; 22.4666; 22.3271; 16.5076; 24.6678; 15.7321; 26.3534; 17.7200]
Please If anyone could help me.

data=rand(5,6);[M,N]=size(data);d=zeros(M*(M-1)/2,1);count=0;for i=1:M-1    for j=2:M        if((i~=j)&&(i<j))            count=count+1;                for k=1:N                d(count)=d(count)+(data(j,k)-data(i,k))^2;            end            d(count)=(0.25*d(count))^(1/2);        end           endend