×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

file names handling in matlab

file names handling in matlab

file names handling in matlab

(OP)
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.

RE: file names handling in matlab

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.

RE: file names handling in matlab

(OP)
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.

RE: file names handling in matlab

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.

RE: file names handling in matlab

(OP)
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.

RE: file names handling in matlab

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.

RE: file names handling in matlab

(OP)
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

RE: file names handling in matlab

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.

RE: file names handling in matlab

(OP)
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

RE: file names handling in matlab

Does "xxx=load(name)" work from the command line?

RE: file names handling in matlab

(OP)
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.

????

RE: file names handling in matlab

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:  14@120.Yo7Kaa4Ebez" TARGET="_new">http://newsreader.mathworks.com/WebX?14@120.Yo7Kaa4Ebez^0@.ee9988d
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".

RE: file names handling in matlab

(OP)
thanks a lot lewish. I'll try that link. Good luck out there!

RE: file names handling in matlab

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
http://www.geocities.com/bstex2001

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources