Borrar filtros
Borrar filtros

Importing data to 3D array in matlab

5 visualizaciones (últimos 30 días)
Jaclyn Rebstock
Jaclyn Rebstock el 2 de Mzo. de 2024
Editada: Voss el 3 de Mzo. de 2024
I'm trying to import many data files that contain x and y (wavenumber/intensity) data into a 3D array. Each data file has a different number of x and y data points. I'm having trouble getting each data set imported into my 3D array since they are all different sizes and I get an error message that the size of the left side doesn't match the right side after the first iteration in the for loop. Any help on getting it to work would be appreciated!
dir = "../Data Dump/Process Data/";
file_type = '*.asc';
%%%create datastore
Datastore = datastore(dir+file_type,"ReadSize","file","VariableNames",["wavenumber","intensity","rand"]);
reset(Datastore)
nfiles = length(Datastore.Files);
file_names = erase(Datastore.Files,dir)';
for n =1:nfiles
T = importdata(file_names{n});
Data(:,:,n) = [T(:,1) T(:,2)];
end

Respuesta aceptada

Voss
Voss el 2 de Mzo. de 2024
Since each file has a different number of x,y, it'll be more convenient to use a cell array:
Data = cell(1,nfiles);
for n = 1:nfiles
T = importdata(file_names{n});
Data{n} = T(:,[1 2]);
end
  2 comentarios
Jaclyn Rebstock
Jaclyn Rebstock el 2 de Mzo. de 2024
This was a perfect solution. Thank you!
Voss
Voss el 3 de Mzo. de 2024
Editada: Voss el 3 de Mzo. de 2024
You're welcome! Any questions, let me know.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by