reading files and data into matlab

2 次查看(过去 30 天)
Hale
Hale 2013-7-16
Hi,
I'm very new to matlab coding and I hope that you guys can help me with this simple matlab code. I'm having trouble in reading some files from different directories. The following screen shot shows the location of the files that I want to read.
In processor1 directory, there are files for each time step. I need to read all the files in those directories except directory 0 and constant which has to be skipped. And then the files for each variable e.g. alpha1 should be imported and finally I want to sort them in ascending order.
I have tried the following but it only gives the name of the foldes at each time step. How to I enter the subfolder and read the files?
I really appreciate any ideas.
  2 个评论
Jan
Jan 2013-7-16
What exactly is a "time step" here?
Hale
Hale 2013-7-16
The data are given for 120 sec and there is an output every 0.1 sec i.e. 0.1 is the time step. The time vector is 0:0.1:120.

请先登录,再进行评论。

回答(3 个)

Jan
Jan 2013-7-16
编辑:Jan 2013-7-16
I suggest to take a look into the FileExchange and use one of the many recursive file importers.

Grzegorz Knor
Grzegorz Knor 2013-7-16
Enter to subfolders: cd
Exit from subfolders cd ..
Read files: importdata

Hale
Hale 2013-7-17
Hi again,
I have now solve the problem with accessing the folder but I still have problem reading the files. When I call the readFvScalarField function it returns a vector of NaN which means that it couldn't find the files with the name 'boundaryFlux_outlet'. It is really weird since the vector 'files' contains the files with the name 'boundaryFlux_outlet'. Am I doing anything wrong in entering the specific folder or reading the files?
Thanks a lot
  1 个评论
Jan
Jan 2013-7-18
Please do not post questions in the section for answers. Adding the source code as formatted code is much better than adding a picture, because we can copy&paste the code to suggest improvements.
When you omit the brute clearing header containing the "clear all", you could use the debugger to check, what's going on in your code. Set a break point in the first line, step through the code line by line and check the value of the local variables. But unfortunately the frequently occurring "clear all" deletes all break points. Ugly. So remove it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by