how to convert from table to 3D array
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello, I have a 1989 x 8 table with column names [ wavelength, Dark, Reference, Amplitude_Capture1, Amplitude_Capture2, Amplitude_Capture3, Amplitude_Capture4, Amplitude_Capture5] I would like to create a 3D array from this table with every first column of the array to be the information of the Wavelength and every second column the amplitude_capture. This would result in:
- Wavelength and Amplitude_Capture1 in My_Array(:,:,1)
- Wavelength and Amplitude_Capture2 in My_Array(:,:,2) etc.
I solved this know with the following code:
% code
for i = 1:1:FolderIndex-1
%cd (MyFolderInfo(i).folder)
name=MyFolderInfo(i).name
Names(1,i)=name
MyTable=importfile(name,3,inf)
TableToArrayStr(:,1:8)=table2array(MyTable(:,1:8));
while ColIndex < 9
AmplitudeArray(:,4,(ArrayDimension+Index))=TableToArrayStr(:,ColIndex)
AmplitudeArray(:,1:3,(ArrayDimension+Index))=TableToArrayStr(:,1:3)
Index = Index+1
ColIndex=ColIndex+1
end
ColIndex=4
end
this is a time consuming effort I wonder if it can be faster / optimized.
I did allocate the Arrays before use.
Thanks.
댓글 수: 0
답변 (1개)
Peter Perkins
2018년 8월 3일
Based on your description, it sounds like you want to horzcat the amplitudes, reshape them into 3D, and prepend (copies of?) the wavelengths. Something like
amps = mytable{:,{'Amplitude_Capture1 ...'Amplitude_Capture5'}};
wavelens = mytable.Wavelength;
ampsData = [repmat(wavelens,1,1,5) reshape(amps,[],1,5)]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!