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

2 ビュー (過去 30 日間)
Lameck Amugongo
Lameck Amugongo 2020 年 3 月 16 日
回答済み: dpb 2020 年 3 月 17 日
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
Lameck Amugongo
Lameck Amugongo 2020 年 3 月 16 日
Thank you so much. This worked.

サインインしてコメントする。

回答 (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 Center および File ExchangeWhos についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by