Code doesn't work with different path
Show older comments
Hi, I have some code* which works well when I define the path to be my Dropbox (installed on the hard disk):
data_path = fullfile('/Users/me/Dropbox/folder/subfolder')
Now, I copy the 'subfolder' from above on a stick and specify the path as follows:
data_path = fullfile('/Volumes/Mystick/subfolder')
With the new path, I try to run the code* again. Now I get an error message. I have verified several times that the new path is correct. The piece of code below is part of a loop. When I ask Matlab how many files it finds in the loop, it finds more with the new path (even though I only copied the folder). This is why I suspect that there are some "hidden" files which provoke the error. Specifically, the error concerns
line= fgetl(f);
Error using fgets
Invalid file identifier. Use fopen to generate a valid file identifier.
Has anyone experienced a similar problem?
*This is the (relevant part of the) code - however, I don't think there is a problem with the code as such because it works perfectly with the first path.
f = fopen(filename_x);
% Read the first line and get the header line
line= fgetl(f);
% Split up the headers
headers = strsplit(line, ',');
% Read the rest of the data
data = textscan(f, '%d%d%f%f', 'Delimiter', ',');
% Reconstruct the data
out_x = [num2cell(data{1}) num2cell(data{2}) num2cell(data{3}) ...
num2cell(data{4})];
% Place the headers
out_x = [headers; out_x];
% Close the file
fclose(f);
Accepted Answer
More Answers (0)
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!