"Invalid file identifier. Use fopen to generate a valid file identifier."
You will typically get this error because the file id that fopen gave you is -1 which indicates that fopen failed to open the file.
There are many reasons why fopen could fail to open the file. The most likely one is because you asked it to open a file that didn't exist (at least in the location where you told it to look).
For a start you retrieve the path of the selected with uigetfile but never tell fopen to look in that path.
filenames{file} = fopen(fullfile(path, inputfile));
may fix the problem. Of course, you should always check that fopen succeeded, so add:
if filenames{file} == -1
error('Failed to open file "%s"', fullfile(path, inputfile));
end
I would strongly recommend renaming that filenames variable to something else, fileids maybe as it absolutely does not contain filenames. It contains file indentifiers: numbers.
Also, I would strongly recommend opening, reading, and closing the file in the same loop rather than doing it over 3 different loops. However, if you're using any reasonably recent version of matlab, I'd recommend using readtable instead of textscan. readtable should figure the format of the file on its own, and opens and closes the file for you.
Finally, note that numbered variables are always a bad idea, forcing you to write a lot more code than necessary. Here you could have created wholedff with just:
0 Comments
Sign in to comment.