From: Ravindra Dwivedi on
Hi group,

I've two questions related to MATLAB, and I'd really appreciate if anybody can provide me any suggestion (s) to resolve the issues.

1) I created 100 data sets using a geostat software. The datasets are named as A.001, A.002, A.003, ..., A.100. How can I read all these data sets separately? I tried using a for loop with variable i, and indicated different file names by using A.00i, so that matlab can read them separately. But, matlab does not like it. How can I read the data sets separately?

2) When I export a different data set from maltab, it export the data in binary format. So, the software tool that I'm using for hydrological modeling is having a hard time to read the data, and often makes mistakes. How can I export data from matlab in a simple DOS format, in which there is a space between two numbers and all new rows start from a new lines.



Ravindra,
From: dpb on
Ravindra Dwivedi wrote:
> Hi group,
>
> I've two questions related to MATLAB, and I'd really appreciate if
> anybody can provide me any suggestion (s) to resolve the issues.
>
> 1) I created 100 data sets using a geostat software. The datasets are
> named as A.001, A.002, A.003, ..., A.100. How can I read all these data
> sets separately? I tried using a for loop with variable i, and indicated
> different file names by using A.00i, so that matlab can read them
> separately. But, matlab does not like it. How can I read the data sets
> separately?

FAQ

<http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_process_a_sequence_of_files.3F>

> 2) When I export a different data set from maltab, it export the data in
> binary format. So, the software tool that I'm using for hydrological
> modeling is having a hard time to read the data, and often makes
> mistakes. How can I export data from matlab in a simple DOS format, in
> which there is a space between two numbers and all new rows start from a
> new lines.
....

If the other tool can read a binary format at all it certainly wouldn't
be "making mistakes". One presumes this means it can't or at least
you're not using the option to do so correctly or it requires something
more than just a straight binary file.

help iofun

particularly useful could be

help dlmwrite

You'll want to remember Matlab internal storage is column-major order so
you'll want to transpose the data array on output to put it in row-major
order.

--
From: Richard Willey on
Hi Ravindra

The dataset array that ships with Statistics Toolbox might offer a nice
solution to some of your problems.

Lets start with Problem 2.

The dataset array has an "export" method which gives you a lot of options
for exporting panel data to a txt file.
The following portion of the Stats Tbx doc discusses the data set array.

http://www.mathworks.com/access/helpdesk/help/toolbox/stats/dataset.export.html

Moving back to Question 1.

I'm going to attach some MATLAB code that I used to

1. Find all the Excel spread sheets in a directory
2. Copy all of the data from these spreadsheets into a dataset array
3. Create a nominal variable based on the file name that I can use to track
what data came from where

It shouldn't be that difficult to modify this code to support your use case.
(Please note, I used Parallel Computing Toolbox to make this all run faster,
hence the use of a parfor rather than a for loop)

regards,

Richard
% This script assumes that we have a set of XLS files

% Each XLS file contains a separate spark sweep

% We're interested in combining all these files into a dataset array

% After which, we're going to identify the minimum BSFC for each spark

% sweep


%Identify where to search for files


Location = 'H:\Documents\MATLAB\BSFC\';


% Store the name of all .xls files as a vector D

D = dir([Location, '*.xls']);


% Create a dataset array from the file that is the first element in D

name = D(1) .name

Engine = dataset('xlsfile',name);


% Use the name of the file as a nominal variable

% The nominal variable can be used to note that all these rows came from

% the file with name = "name"


% Start by stripping off the ".xls" extension

name = name(1:end-4);


% Write the name to the dataset array and convert to a nominal

Engine.Name = repmat(name,length(Engine),1);

Engine.Name = nominal(Engine.Name);


% Repeat for all the rest of the .xls files in the "Location".

% Each new file with be vertically concatenated with the

% original dataset array


f = @(x,y) vertcat(x,y);


parfor i = 2 : length(D)


name = D(i) .name

Engine2 = dataset('xlsfile',name);


name = name(1:end-4);

Engine2.Name = repmat(name,length(Engine2),1);

Engine2.Name = nominal(Engine2.Name);


Engine = f(Engine, Engine2);


end



"Ravindra Dwivedi" <ravindra(a)nmt.edu> wrote in message
news:i3c51c$fp9$1(a)fred.mathworks.com...
> Hi group,
>
> I've two questions related to MATLAB, and I'd really appreciate if anybody
> can provide me any suggestion (s) to resolve the issues.
>
> 1) I created 100 data sets using a geostat software. The datasets are
> named as A.001, A.002, A.003, ..., A.100. How can I read all these data
> sets separately? I tried using a for loop with variable i, and indicated
> different file names by using A.00i, so that matlab can read them
> separately. But, matlab does not like it. How can I read the data sets
> separately?
>
> 2) When I export a different data set from maltab, it export the data in
> binary format. So, the software tool that I'm using for hydrological
> modeling is having a hard time to read the data, and often makes mistakes.
> How can I export data from matlab in a simple DOS format, in which there
> is a space between two numbers and all new rows start from a new lines.
>
>
>
> Ravindra,