How can I load multiple dat files of different name pattern and from different directory consecutively to do something
Show older comments
Hi, I have some dat files of row*Column( 9999*10 )of names:
dir1/a_0.1_1
dir1/b_0.1_2
dir1/c_0.3_1
dir1/c_1.5_1
dir2/a_0.1_1
dir2/a_0.5_1
Now How can I load and recall then sequentially to do something? is there any short cut for loop for this specially when they are in different folder? Thank you
Accepted Answer
More Answers (5)
az
on 22 May 2018
0 votes
3 Comments
Ameer Hamza
on 22 May 2018
You need to download the files from FEX and place it in the current folder of MATLAB. The current folder is the folder which is displayed in Current Folder window in MATLAB.
Now, suppose that you have a folder structure like this
B: <- B drive for you computer
other folders in the path
folderTop <--- this folder contains all the .dat files
folder1
file1.dat
file2.dat
...
folder2
file1.dat
file2.dat
...
folder3
file1.dat
file2.dat
...
You can use subdir() as follow
files = subdir('B:/other folders/folderTop/*.dat');
It will give you the similar struct given by dir but containing files in all the subfolders. You can use the remaining code same as before.
az
on 22 May 2018
Ameer Hamza
on 22 May 2018
For NaN you can use fillmissing() to replace values. Since you also want to deal with inf in the same way, so first replace all inf with NaN and then use fillmissing(). For example
x = [1 2 inf 8 9 nan 15];
x(isinf(x)) = nan;
fillmissing(x, 'linear') % using linear will avoid repeated values.
ans =
1 2 5 8 9 12 15
az
on 23 May 2018
0 votes
az
on 23 May 2018
0 votes
1 Comment
Ameer Hamza
on 23 May 2018
Can you explain again, which variable have different lengths and which function is causing the error?
az
on 23 May 2018
0 votes
az
on 23 May 2018
0 votes
4 Comments
Ameer Hamza
on 23 May 2018
First thing, you are not replacing the missing values because the command
fillmissing(x, 'linear');
will not change x. You will need to assign its value
x = fillmissing(x, 'linear');
Also from line 19
m = (1* 10^3/((max(x)- min(x))/9999))
I get
m =
0.0014
If you want to use it in linspace() then it must be an integer.
az
on 23 May 2018
Ameer Hamza
on 23 May 2018
No, You must have all columns of equal length to take mean. Mean will only make sense if all columns have equal lengths. That is why you need to use fixed interpolation.
az
on 23 May 2018
Categories
Find more on Performance and Memory 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!