how to convert from table to 3D array

9 ビュー (過去 30 日間)
Eddy van der Goot
Eddy van der Goot 2018 年 7 月 17 日
回答済み: Peter Perkins 2018 年 8 月 3 日
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.

回答 (1 件)

Peter Perkins
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)]

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by