Matlab Import and combine multiple dat files

1 回表示 (過去 30 日間)
Yan Rui Lee
Yan Rui Lee 2017 年 12 月 26 日
編集済み: Birdman 2017 年 12 月 26 日
I am trying to import multiple .dat files, process them and combine into a single matrix. In this case, I need to divide each cell by its time (i.e. normalizing factor). This example is for 2 dat files, I managed to do it, but I have a lot of files, up to data100raw, and I hope to have a loop to process everything in one go, while allowing me to set a different normalizing factor for each file.
data1raw = importdata('2015-04-19004-190-31.04-20140819-5sample transport-PL spectra 10s-0mm.dat')
data2raw = importdata('2015-04-19004-190-31.04-20140819-5sample transport-PL spectra 10s-2mm.dat')
%remove first column
data1raw(:,1) = []
data2raw(:,1) = []
%Enter time (i.e. normalising factor)
data1time = [5; data1raw]
data2time = [10; data2raw]
%combine
datacombine = [data1time, data2time]
%normalise
width = 2
height = 1341
for ihori = 1:width
for iverti = 2:height
datacombine(iverti,ihori) = datacombine(iverti,ihori) / datacombine(1,ihori)
end
end
Screenshots of original data
and final desired product (first row is the normalising factor)

回答 (1 件)

Birdman
Birdman 2017 年 12 月 26 日
Below, I made a simple example where I assumed that you have 3 set of datas which have 10 row each and already uploaded(I skipped the part before combine).
datacombine=randi([600 615],10,2,3);%random data
width = size(datacombine,3);
height = size(datacombine,1);
for i = 1:width
fac=input('Enter normalising factor\n');
datacombine(:,:,i) = [(datacombine(:,1,i)./fac(1)) (datacombine(:,2,i)./fac(2))];
end
With this, you can define new normalising factor for each set of data in the loop. Hope this approach helps.
  2 件のコメント
Yan Rui Lee
Yan Rui Lee 2017 年 12 月 26 日
Hi Birdman, I got an error that index exceeds matrix dimension </matlabcentral/answers/uploaded_files/99531/Error.png>
Btw for this line
datacombine(:,:,i) = [(datacombine(:,1,i)./fac(1)) (datacombine(:,2,i)./fac(2))];
if I have 100 dat files do I have to copy and paste till fac(100)?
Birdman
Birdman 2017 年 12 月 26 日
編集済み: Birdman 2017 年 12 月 26 日
From my code, you should not receive any error. Be careful while adapting mine to yours.
When you said 100 dat files, I thought them of 100 times separate 10 rows of files, like
datacombine=randi([600 615],10,2,100);
By the way, when you enter factors at each loop, enter them as follows:
[5 10]
[2 4]
[1 3]

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by