Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

file names handling in matlab

Status
Not open for further replies.

hobbit02

Marine/Ocean
Jun 17, 2002
9
Hi there,
I know this may be a trivial question, but I am having trouble solving this.

I need to enter a file name from keyboard while matlab is running a script. I have been trying CASEREAD, UIGETFILE and others similar.

I can enter the name correctly, but under the assigned name it is stored only the used string, not the file itself.

for example, if I use

[name path]=uigetfile

to enter from the keyboard "sales.txt"

and then use


load(name)

the file "sales.txt" is loaded, but if I then use

size(name)

it gives me the size of the string used to name the matrix, not the size of the matrix itself, which is what I need to know.

Hope you can help me.
Thanks a million.
 
Replies continue below

Recommended for you

Use the following:

XXX=load(name);

This will store the ascii contents of your file in a variable named XXX. Then you can use size(XXX) to get the information you desire.

Good luck.
 
thanks a lot but I've tried that and see what I get:

[name path]=uigetfile

name =

copruebax


path =

C:\series
» xxx=load(name);
??? Error using ==> load
Too many output arguments.

 
That message would seem to indicate that Matlab thinks your file contains multiple matrix. Or, that you have multiple variables in the input file.

Tell me more about your input file.
 
Hi Lewish,
Thanks for your interest.
Actually, the file used for the example above is quite simple.
copruebax is a vector of length=6000
and its first 10 elements are:

-3.0280
-11.0031
2.1686
3.8995
-5.6043
11.2166
11.5737
3.2546
5.9693
4.9490
I can't think of any problem with this file.
Thanks again, and hope to hear from you soon.
 
Hi Hobbit02, Hmmm, the only other thing I can think of at the moment is, you may have a problem with your delimiters. What are you using to delimit the values? Is there a carriage return anywhere in the file? This could cause matlab to think you have more than one variable.
BTW, what version of Matlab are you using. There are slight differences between versions.
 
Hi Lewish,
Well, the version I am using is 5.0.
the file I put as an example was also generated with Matlab. And there is nothing unusual in that file.
Even more, I have tried with many files which otherwise work perfectly with matlab.
The only thing I can't do is giving the name of a file to be used in a script, without getting into the M file editor. The problem is that I am writing a script which is going to be used by another person who is not familiar with matlab and I am trying to make it easier for that other person.
I am sure there has to be a way to do it, but I don't know it.
Ok, I'll keep trying.
Take care, and thanks
 
Hi Hobbit, if you execute your June 17 posting inside the command window, does it work correctly? I am using version 6.1, so I don't know if it will work correctly with 5.0.
 
Hi Lewish,
Actually it gets to load the file, but when you ask for example how many columns or rows does the matrix have (using the name assigned in the uigetfile command), it gives you the size of the string used to name te matrix.
see you
 
Does "xxx=load(name)" work from the command line?
 
for example;
If I do:

[name path]=uigetfile;
fname=[path name];
load(fname)


I get to load the file under the name I specify in the dialog window which pops up after uigetfile (e.g. try.dat)
So, since now fname='c:\...\try.dat'
Any time I try to do something with fname I am referred to the string 'c:\...\try.dat', not to the file under this name.
If you type WHOS, you will see your file try.dat there, with all its rows and columns, but I have not found the way to use the file.
If I use xxx=load(fname) I get this:


» xxx=load(name);
??? Error using ==> load
Too many output arguments.

it looks like LOAD doesn't like to have anything on its left.

????
 
Hi Hobbit, I am afraid I can't be of any more help. I no longer have 5.x loaded, so I can't try to get a solution.
However, here is a link where you can post the question and hopefully get more help:
There are people there who use the older versions of Matlab.
Good Luck.
Note: the markup language used by this system is having trouble with the link I inserted. Use the part from "http" to the "ee9988d".
 
thanks a lot lewish. I'll try that link. Good luck out there!
 
Hi,
It may be that the output is a cell or a structure. In this case you will get an answer for size(name) 1x1.
Try class(filename).
Another thing:
If you save the data using save ... -ascii you can use load.
If you save it using fwrite than use fread to load it.
If you save it using fprintf than use fscanf to load it.

Joe
BSTEX - Equation viewer for Matlab
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor