# How to fill a matrix from 11,000x43 to 32,000x43 with Nans in order to concatenate arrays?

1 view (last 30 days)
Andres Ulloa on 3 Aug 2022
Edited: Andres Ulloa on 3 Aug 2022
I am trying to generate a 3D array with 100 different files, however there are 30 files that are 11,000x43 and 70 that are 32,000x43. I would like to be able to make them the same size so I can concatenate them.
This is my example:
close all; clear all
S = dir(fullfile(P,'S1*.mat'));
S = natsortfiles(S);
for k = 1:numel(S)
F = fullfile(P,S(k).name);
v1(k).data = L.Data.Burst_VelBeam1;
end
vb1 = permute(cat(3,v1.data),[1,3,2]);
save('velbeam1_3.mat','vb1')
....

Image Analyst on 3 Aug 2022
Why do they have to be nan? Can they be zeros? If so the easy way is
close all;
clear all
S = dir(fullfile(folder,'S1*.mat'));
S = natsortfiles(S);
for k = 1:numel(S)
fullFileName = fullfile(folder,S(k).name);
% Get the image from the recalled structure.
thisMatrix = L.Data.Burst_VelBeam1;
% Check it's size, expanding if necessary.
if k == 1
[rows, columns, numberOfColorChannels] = size(thisMatrix);
else
[rowsk, columnsk, numberOfColorChannelsk] = size(thisMatrix);
if rowsk < rows || columnsk < columns
% This matrix is smaller. Expand it to the same size as the
% first image.
thisMatrix(rowsk, columnsk) = 0;
end
end
% Assign to the data field of the k'th structure.
v1(k).data = thisMatrix;
end
vb1 = permute(cat(3,v1.data),[1,3,2]);
save('velbeam1_3.mat','vb1')
Andres Ulloa on 3 Aug 2022
I attach 2 examples, hope they help.

### Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

R2015a

### Community Treasure Hunt

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

Start Hunting!

Translated by