Create a maxtrix of row x columns and add values (column-wise) in a loop

2 vues (au cours des 30 derniers jours)
Lameck Amugongo
Lameck Amugongo le 16 Mar 2020
Réponse apportée : dpb le 17 Mar 2020
I am trying to add matrix with the same number of rows to a bigger matrix column-wise in a loop. How do i do this?
%The big array to store all values
bigArray = zeros(size(array1,1), size(array4D,4)*5); %23333 x 35
for jac=1:size(array4D,4)
jacMap = array4D(:,:,:,jac); % Get an image from array
for k=1:size(dataCoords,1)
%Array to store extracted values in each image at the 5 sampling points
singleArray = zeros(size(array1,1),5); %23333 x 5
row = dataCoords(k,:);
row = table2array(row);
%Lets seperate the coordinates for each point (5 sampling points)
ptX = (row(1:5));
ptY = (row(6:10));
ptZ = (row(11:15))
%extract values from image
%Interpolate at the
Vq = interp3(jacMap, ptX, ptY, ptZ);
singleJac(k,:) = Vq;
end
%For each image add singleJac array to bigArray - starting at 1:5 then 6:10 then 11-15, 16-20 ... 31-35 (colomn-wise)
%note Single jac and bigArray have the same number of rows
bigArray(:,1:5) = singleJac(:,:);
end
  4 commentaires
dpb
dpb le 16 Mar 2020
j=0; % initialize other array counter
for i=1:5:size(bigArray,2) % 1:6:11 ...
j=j+1;
data=importdata('Yourfile(j)'); % get the data from the files..
bigArray(:,i:i+4)=data; % put into the big array
end
Lameck Amugongo
Lameck Amugongo le 16 Mar 2020
Thank you so much. This worked.

Connectez-vous pour commenter.

Réponses (1)

dpb
dpb le 17 Mar 2020
Comment moved to Answer since did seem to be the Q? asked...
j=0; % initialize other array counter
for i=1:5:size(bigArray,2) % 1:6:11 ...
j=j+1;
data=importdata('Yourfile(j)'); % get the data from the files..
bigArray(:,i:i+4)=data; % put into the big array
end

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by