Looping for storing differet matrix in different rows but in same matrix.

1 vue (au cours des 30 derniers jours)
Hello everyone,
I have got a 3x2 cell "alpha_data" in which each cell consists of 1x79 matrixs in them (shown below Fig2). I want to get all these 1x79 matrixes in one matrix "Calculated_Data", so as to have a final matrix of 6x79. i.e. All data into one matrix with all individuals cell matrixs goes into one matrix different rows. I wrote this code but its only giving me one alpha_data{3,2} (Fig 1)data into "Calculated_Data" matrix
for i = 1:size(alpha_data,1) %size(alpha_data,1) = 3
for j = 1:size(alpha_data,2) %size(alpha_data,1) = 2
Calculated_Data = vertcat(alpha_data{i,j});
end
end
The above code that I wrote is only giving one cell's data into final matrix.
Fig1. "Calculated_Data"only giving me one alpha_data{3,2} , but I need 6x79 (all data in the same matrix)
Fig 2. alpha_data: A 3x2 cell, each cell have 1x79 matrix
Any helps would be greately appreacited.

Réponse acceptée

Vladimir Sovkov
Vladimir Sovkov le 1 Déc 2019
Before the loop, initiate
Calculated_Data=zeros(numel(alpha_data),numel(alpha_data{1,1}));
k=0;
within the loop, use
k=k+1;
Calculated_Data(k,:) = alpha_data{i,j};

Plus de réponses (1)

Bhaskar R
Bhaskar R le 1 Déc 2019
Modifié(e) : Bhaskar R le 1 Déc 2019
In simple way
Calculated_Data = reshape([alpha_data{:}],6,79);
In for loop
Calculated_Data = zeros(6, 79);
k = 1; % counter variable
for i = 1:size(alpha_data,1) %size(alpha_data,1) = 3
for j = 1:size(alpha_data,2) %size(alpha_data,1) = 2
Calculated_Data(k,:) = alpha_data{i,j};
k = k+1;
end
end
  3 commentaires
Bhaskar R
Bhaskar R le 1 Déc 2019
Yes, my apologies
Darpan Verma
Darpan Verma le 1 Déc 2019
Thanks for replying mate

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by