Problems accessing files from code after moving a matlab project from uni pc to home

1 回表示 (過去 30 日間)
Bojan Poletan
Bojan Poletan 2022 年 5 月 21 日
コメント済み: Bojan Poletan 2022 年 5 月 21 日
I am having a problem when opening files in Matlab. I am working on a course project at uni and I should use a fully working code provided by teachers and make some practice with it.
Unfortunately, after installing matlab R2022a and fixed all dependencies, after running the file
feature_extraction.m
(as sait in the instructions) I faced the following error:
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in addi_features_from_list (line 11)
file_path = textscan(fid, '%s', 'delimiter', '\n', 'whitespace', '');
Error in feature_extraction (line 33)
[Features, file_path] = addi_features_from_list(fname_in);
Here is the code giving the error:
function [Features, file_path] = addi_features_from_list(file)
fprintf('File: %s \n', file); % Output: File: dat/controlled_config_1_train.dat
fid = fopen(file, 'r');
file_path = textscan(fid, '%s', 'delimiter', '\n', 'whitespace', '');
file_path = file_path{1};
N = length(file_path);
fprintf('\nNumber of images: %d \n', N);
Features = zeros(N, 152);
for i = 1:N
[~,file_name,ext] = fileparts(file_path{i});
fprintf('process file: %s\n', [file_name ext]);
Features(i,:) = addi_features(file_path(i));
end
end
Here is the hirarchy of my working directory (the whole directory has been added to the path):
I also tried to see if the file exists from matlab but I always get a negative answer. Howcan i solve this?
Thanks.
PS: I am using MacOS (I also tried on Win 10)
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 21 日
You have not shown us the content of fname_in
Bojan Poletan
Bojan Poletan 2022 年 5 月 21 日
Fname_in is the same as file:
dat/controlled_config_1_train.dat

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2022 年 5 月 21 日
Do not call fopen without checking for errors:
[fid, msg] = fopen(file, 'r');
assert(fid > 0, 'Cannot open file for reading: %s', file);
In the commen you mention, that file is "dat/controlled_config_1_train.dat".
The screenshot shows, that such a file does not exist, but:
dat/controlled_config_3_train.dat
% ^
  1 件のコメント
Bojan Poletan
Bojan Poletan 2022 年 5 月 21 日
You are right. But this is very strange... Probably the error is somewhere else. I will contact the teacher.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by