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

5 次查看(过去 30 天)
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 个评论
dpb
dpb 2020-3-16
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

请先登录,再进行评论。

回答(1 个)

dpb
dpb 2020-3-17
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

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by