Efficiently Import and Organize Topographic Profile Data in Matlab

  • Context: MATLAB 
  • Thread starter Thread starter rocks rock
  • Start date Start date
  • Tags Tags
    Data files Matlab
Click For Summary
SUMMARY

This discussion focuses on efficiently importing and organizing topographic profile data in MATLAB using CSV files. The user encounters an "Error File Not Found" issue when certain profile files are missing. Solutions provided include implementing a try...catch statement to handle errors gracefully and utilizing the dir or ls commands to check for file existence before attempting to read them. Additionally, strategies for zero-packing missing values are suggested to maintain data integrity.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax
  • Understanding of CSV file structure and data types
  • Knowledge of error handling in MATLAB using try...catch
  • Experience with file management commands in MATLAB, such as dir and ls
NEXT STEPS
  • Implement error handling in MATLAB using try...catch statements
  • Explore the use of dir and ls commands for file management in MATLAB
  • Research methods for zero-packing missing data in MATLAB matrices
  • Learn about advanced data organization techniques in MATLAB for time-series data
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and researchers working with time-series topographic data who need to manage missing files and ensure efficient data importation and organization.

rocks rock
Messages
3
Reaction score
0
Hi. I am trying to read csv files into Matlab. The files are x, y, z values for topographic profiles taken about 4 times a year over several years. I've worked out how to loop through each file and loop through names so that each comes in as a separate matrix. (see below) The problem I'm having is that some profiles are missing for certain years or seasons. So when Matlab comes to one of those files it says "Error File Not Found." I'm wondering if there is a way to skip over files that just don't exist.

Thanks

File naming scheme: prof_#_seasonyear
Ex: prof_3_sp08

Sample of code I'm using:

for i = 2:49
fname=sprintf('prof_%d_sp99.out',i);
eval(['sp99_prof_' num2str(i) '= csvread(fname);'])

fname=sprintf('prof_%d_sp00.out',i);
eval(['sp00_prof_' num2str(i) '= csvread(fname);'])

fname=sprintf('prof_%d_sp01.out',i);
eval(['sp01_prof_' num2str(i) '= csvread(fname);'])

end
 
Physics news on Phys.org
You could also use the dir or ls commands in MATLAB (once you've set the directory) to get a directory listing (I think both will work regardless of whether it's in a Windows / Linux / Mac environment):
http://www.mathworks.com/help/techdoc/ref/dir.html
http://www.mathworks.com/help/techdoc/ref/ls.html

You can also use this with a little more code to zero pack in place of missing values (assuming this is desirable). Or just insert zeros whenever you catch errors (as jhae2.718 suggests).
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
7K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
10K
  • · Replies 2 ·
Replies
2
Views
11K