Using regexp on a double array

I'm trying to extract variable names and years from my file names, but getting an error from regexp.
Example of code:
%Call up files
pwd
fuf(pwd, 'detail');
fn=fuf(['/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/*shtfl.nc*'],'detail');
load(char(fn{1}));
%Extract variable names
pieces = regexp(fn, '\/', 'split');
p=pieces{1};
driver = p{9};
but I get this error message:
Undefined function 'regexp' for input arguments of type 'double'.
Is there a different function I should be using on double arrays? Thanks!

9 commentaires

Tom
Tom le 24 Juin 2013
fn appears to be a cell based on the load line, what does it consist of?
Jan
Jan le 25 Juin 2013
Modifié(e) : Jan le 25 Juin 2013
What is fuf? What is the contents of fn{1} and is it required to convert is to a char?
Perhaps the operating system prevents that a user called "Tom" operates in the directory of "Katharyn Woods"?
Walter Roberson
Walter Roberson le 25 Juin 2013
If "fn" is a cell so that fn{1} is a string that is the name of a file, then the only way that fn can be double two lines later is if the load() is clobbering "fn".
It is not completely impossible that fn{1} is a numeric value or vector that char() can be applied to in order to get a file name, but it seems unlikely.
Kate
Kate le 25 Juin 2013
Modifié(e) : Kate le 25 Juin 2013
fn (filename) is just a variable that I'm using to save all of the files that fuf (files under folder function) pulls up. The output of the first segment is the following:
ans =
/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/.DS_Store'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/metgrid.mat'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1900.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1901.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1902.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1903.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1904.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1905.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1906.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1907.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1908.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1909.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1910.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1911.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1912.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1913.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1914.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1915.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1916.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1917.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1918.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1919.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1920.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1921.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1922.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1923.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1924.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1925.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1926.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1927.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1928.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1929.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1930.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1931.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1932.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1933.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1934.nc'
'/Users/katharynwoods/Documents/MATLAB/Research/MATLAB/flux_sensitivity_analysis/Met_drivers/sens_heat/shtfl.1935.nc'
and so forth. I would basically like to split this to extract variables (ex: years).
Tom
Tom le 25 Juin 2013
When you load fn{1}, are any of the variables that you load also called fn?
Kate
Kate le 25 Juin 2013
Also, you won't be able to call up under fuf, because that command line is essentially my path to my folders. The fuf works perfectly, it's the regexp and split that I'm having trouble with.
Thanks everyone for your help! It's greatly appreciated.
Then load() must be replacing "fn".
Put a breakpoint in before the load. Examine class(fn) . "step" past the load. Examine class(fn). Has it changed? What does
which regexp
return?
Kate
Kate le 25 Juin 2013
Walter, now I see what you're saying. Perhaps this is a netcdf issue. I wrote this code for .m files and it worked fine, but now my fn is empty when I use it on .nc files. Frustrating.
per isakson
per isakson le 25 Juin 2013
Modifié(e) : per isakson le 25 Juin 2013
Matlab (R2012a) does not have a function, load, which reads NetCDF-files.
Doc says: ncdisp, Display contents of NetCDF data source in Command Window
Try
ncdisp( '[...]alysis/Met_drivers/sens_heat/shtfl.1902.nc') % use full name
and read the documentation on NetCDF

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Data Import and Analysis dans Centre d'aide et File Exchange

Produits

Question posée :

le 24 Juin 2013

Community Treasure Hunt

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

Start Hunting!

Translated by