简体   繁体   中英

SOM Algorithm Matlab HELP

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);

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

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM