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

2 visualizaciones (últimos 30 días)
Lameck Amugongo
Lameck Amugongo el 16 de Mzo. de 2020
Respondida: dpb el 17 de Mzo. de 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 comentarios
dpb
dpb el 16 de Mzo. de 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

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 17 de Mzo. de 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

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by