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.
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
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
[name path]=uigetfile
name =
copruebax
path =
C:\series\
» xxx=load(name);
??? Error using ==> load
Too many output arguments.
RE: file names handling in matlab
Tell me more about your input file.
RE: file names handling in matlab
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
BTW, what version of Matlab are you using. There are slight differences between versions.
RE: file names handling in matlab
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
RE: file names handling in matlab
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
RE: file names handling in matlab
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
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
RE: file names handling in matlab
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