Matlab Import and combine multiple dat files
1 view (last 30 days)
Show older comments
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)

0 Comments
Answers (1)
Birdman
on 26 Dec 2017
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 Comments
Birdman
on 26 Dec 2017
Edited: Birdman
on 26 Dec 2017
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]
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!