필터 지우기
필터 지우기

Importing data to 3D array in matlab

조회 수: 5 (최근 30일)
Jaclyn Rebstock
Jaclyn Rebstock 2024년 3월 2일
편집: Voss 2024년 3월 3일
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

채택된 답변

Voss
Voss 2024년 3월 2일
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
Jaclyn Rebstock
Jaclyn Rebstock 2024년 3월 2일
This was a perfect solution. Thank you!
Voss
Voss 2024년 3월 3일
편집: Voss 2024년 3월 3일
You're welcome! Any questions, let me know.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by