ap123
ap123

Reputation: 31

Storing output from each for loop iteration in MATLAB

Say I have 3 matrix data files in a folder..

I have a function (clustering_coef_bu) which calculates the clustering coefficient of a 2D matrix (data; has the dimensions 512x512) file. The output vector of the function creates a 512x1 Matrix (Clustering Coefficient), in double format.

With the for loop below, for each matrix (data) I'm calculating the clustering coefficient. However, I am having difficulties being able to store the output clustering coefficient for each run of the for loop. It would be ideal to output the clustering coefficient of each matrix into one singular structure. I.e a cell array, which has the dimensions 512x3.

for k = 1:3  
     ClusteringCoefficient=clustering_coef_bu(data)
end 

Any help would be great. Thanks.

Upvotes: 0

Views: 1320

Answers (1)

Nick
Nick

Reputation: 3193

Something like this would probably help you:

widthArray = 3;
ClustingeringCoefficient = zeros(size(data, 1), widthArray);

for k = 1:widthArray
    ClusteringCoefficient(:, k) = clustering_coef_bu(data); % a 512x3 double matrix
end 

Upvotes: 2

Related Questions