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

1 view (last 30 days)
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
P = 'D:\2021\datos_cozumel\DatosADCP2\';
S = dir(fullfile(P,'S1*.mat'));
S = natsortfiles(S);
for k = 1:numel(S)
F = fullfile(P,S(k).name);
L = load(F);
v1(k).data = L.Data.Burst_VelBeam1;
vb1 = permute(cat(3,,[1,3,2]);
Thanks for your help

Answers (1)

Image Analyst
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
folder = 'D:\2021\datos_cozumel\DatosADCP2\';
S = dir(fullfile(folder,'S1*.mat'));
S = natsortfiles(S);
for k = 1:numel(S)
fullFileName = fullfile(folder,S(k).name);
% Load the mat file.
L = load(fullFileName);
% 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);
[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;
% Assign to the data field of the k'th structure.
v1(k).data = thisMatrix;
vb1 = permute(cat(3,,[1,3,2]);

Sign in to comment.


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

Community Treasure Hunt

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

Start Hunting!

Translated by