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

1 visualización (últimos 30 días)
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;
end
vb1 = permute(cat(3,v1.data),[1,3,2]);
save('velbeam1_3.mat','vb1')
....
Thanks for your help

Respuestas (1)

Image Analyst
Image Analyst el 3 de Ag. de 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);
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')
  3 comentarios

Iniciar sesión para comentar.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by