tags:

views:

136

answers:

3

I'm trying to pass a txt file to som_read_data from a GUI......i created a function that takes a txt file from the GUI and then passes it to som_read_data..but i'm getting some errors...here are a list of some of the errors.....any one with ideas?

??? Error using ==> ftell
Invalid file identifier.  Use fopen to generate a valid file identifier.

Error in ==> som_read_data at 169
  fpos1 = ftell(fid); c1 = 0;      % read first non-comment line

Error in ==> prog_som at 3
sD = som_read_data(m);
+1  A: 

The error says that your file identifier may not be valid. Did you check?

You get a file identifier (fid in your function som_read_data) by calling fid=fopen(fileName), where fileName is the name of your file if it's in the current directory, or the file name including path name otherwise.

To debug, you may want to call [fid,message] = fopen(fileName) and check whether message is empty. If it's not, there has been an error opening the file, and consequently, fid is not a valid file identifier.

EDIT You may want to look at what message says. My bet is that it is something like 'file not found', either because the file is not on the path, or because you miss the extension.

EDIT2 Look through som_read_data to find which function is returning fid before it is used in line 169. If the line says fid = fopen(m), then you should pass a filename to som_read_data, i..e call som_read_data(B).

Jonas
the line of code used in my GUI to read the file is get the file is:[filename, pathname] = uigetfile( ...{'*.m;*.fig;*.mat;*.mdl','MATLAB Files (*.m,*.fig,*.mat,*.mdl)'; '*.m', 'M-files (*.m)'; ... '*.fig','Figures (*.fig)'; ... '*.mat','MAT-files (*.mat)'; ... '*.mdl','Models (*.mdl)'; ... '*.*', 'All Files (*.*)'}, ... 'Pick a file');B = [filename,pathname];m = textread(B);x = prog_som(m)The variable "m" is now passed onto Prog_som.m as input.....or is dis wrong?
Tim
+1  A: 

The error indicates that either you didn't open a file first, or FOPEN was not able to open the file correctly. If the value of the returned file identifier is -1 after a call to FOPEN, it indicates that an error occurred (such as trying to open a non-existent file).

EDIT:

Based on your comment, you are building the path to your file incorrectly. You should create B as follows:

B = [pathname,filename];  %# Append filename to the end of pathname
%# Or
B = fullfile(pathname,filename);  %# In case pathname doesn't have a file
                                  %#   separator (`\` or '/') on the end

You had the order reversed (B = [filename,pathname];), which would give you an invalid file path and thus an invalid file identifier fid when trying to open the file with FOPEN.

gnovice
the line of code used in my GUI to read the file is get the file is: [filename, pathname] = uigetfile( ... {'*.m;*.fig;*.mat;*.mdl','MATLAB Files (.m,.fig,.mat,.mdl)'; '*.m', 'M-files (*.m)'; ... '*.fig','Figures (*.fig)'; ... '*.mat','MAT-files (*.mat)'; ... '*.mdl','Models (*.mdl)'; ... '*.*', 'All Files (.)'}, ... 'Pick a file'); B = [filename,pathname]; m = textread(B); x = prog_som(m) The variable "m" is now passed onto Prog_som.m as input.....or is dis wrong?
Tim
@Tim: I updated my answer to address a bug in the code in your comment.
gnovice
I tried that but there is still an error......I think i'm lacking a command after uigetfile but before textread??
Tim
@Tim: If your intent is to pass a *file name* to `prog_som`, then you should pass the file path `B`. In the code in your comment, you are reading the text from the file `B` and passing *that text* to prog_som.
gnovice
datz true....and how should dat be done??
Tim
@Tim: Just pass `B` to `prog_som` instead of `m`. Then, inside `prog_som`, make sure you pass the file path along to `som_read_data`, where your error is stemming from.
gnovice
thanks a lot!!!!
Tim
+1  A: 

It looks like you are using som_read_data function from SOMTOOLBOX. The function suppose to get data file name as argument. But you are read the file with textread into m variable and pass it to Prog_som.m, which pass it to som_read_data. I don't know if Prog_som.m does something with m-variable. Anyway try to pass B instead of m:

[filename, pathname] = uigetfile( ...
B = fullfile(pathname,filename);
x = prog_som(B);

Also make sure your file is in SOM_PAK format. You can find it's description in the comments inside som_read_data.m.

yuk
dat worked...thanks....r u familiar with the workings of the som toolbox??
Tim
a little bit ...
yuk
BTW, would you use normal English please?
yuk
ok....i'd like to generate comprehensive plot diagrams with my som algorithm.....how do i go about dat?..
Tim
This should be independent question. What exactly "comprehensive plot diagrams" do you need? Have you run 4 demos in the toolbox?
yuk
possible to get ur email...need to ask some other questions
Tim
Why not to ask here?
yuk
i cn bt got lots of questions to ask...... prefer a conversation probably on msgr.....i cn drop my yahoo or hotmail addy if u dont mind....but if u insist on this site...its fine
Tim
Here is better, Others may help you as well.
yuk
hello yuk, i'm designing a GUI to implement som algorithm......and I want to provide a input box in which a user can specify factors like no of iterations,what distance metric to be used, type of neighbourhood function and initial and final values of neighborhood functions, ...what som toolbox files do i link diz input boxes to nd hw do i code it in matlab???
Tim
Hey....would really like to know what line of code(in wt M-file) in the som toolbox performs the iteration function as well as the line of code for the neighborhood functions...i've been trying to get that for a while nw bt cant....i'd highly appreciate ur help!!!
Tim