Error using load Unable to read file No such file or directory.

326 ビュー (過去 30 日間)
mr de
mr de 2019 年 6 月 25 日
編集済み: Stephen23 2023 年 10 月 29 日
Hi,
I want to run my code but I confront Error using load Unable to read file 'E:\Program Files\MATLAB\R2016a\bin\EegMyDataDir 1\with occular artifact\cnt' No such file or directory
part of the code is below:
Thanks for help!
clc
clear all
warning off all
close all
%% Parameters
K = 0;
Task_time = 10;
subjects_num = 29;
channel_num = 30;
low_cut_off = 1;
high_cut_off = 45;
filter_order = 4;
%% reading and processing
for subj = setdiff(1:subjects_num,21)
load(['E:\Program Files\MATLAB\R2016a\bin\EegMyDataDir ',num2str(subj),'\with occular artifact\cnt'])
load(['E:\Program Files\MATLAB\R2016a\bin\EegMyDataDir ',num2str(subj),'\with occular artifact\mrk'])
  1 件のコメント
Jan
Jan 2019 年 6 月 25 日
Never, never, never store data or user-defined functions inside Matlab installation folder, e.g. E:\Program Files\MATLAB\R2016a\bin. The effects are not predictable.

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

回答 (3 件)

Guillaume
Guillaume 2019 年 6 月 25 日
The error message is very clear, there is no file E:\Program Files\MATLAB\R2016a\bin\EegMyDataDir 1\with occular artifact\cnt
If you intended for that file to exist, then you need to find out why it doesn't. It's nothing to do with matlab.
On the other hand, you should never use any directory in Program Files to store your data. That's a sure way of corrupting your software installation. So I'd recommend you use another directory such as My Documents\Matlab to store you files.
Also, since you don't appear to be very experience with matlab, I would strongly recommend not using warning off all.
  5 件のコメント
Fabiana
Fabiana 2023 年 10 月 16 日
Thanks, @Stephen23. Maybe my doubt should be "how can I informe where are the files that must be read"?
Because I received a script from a colegue:
%%%%%% Analyse des fichiers Alcool
filename = [C:Users\Donnes\G' cell2mat(GROUPE(groupe)) '_S' num2str(suj) '_' cell2mat(SESSION(session)) '.mat'];
datalcool = load(filename);
disp(['Traitement Physio en cours du Sujet ' num2str(suj) '(' cell2mat(GROUPE(groupe)) ' ans) en session alcool ' cell2mat(SESSION(session)) ])
% Voies des données physiologiques : données brutes
EDAraw.valeur = datalcool.mat(:,1);
ECGraw.valeur = datalcool.mat(:,2);
EEG1raw.valeur = datalcool.mat(:,3);
EEG2raw.valeur = datalcool.mat(:,4);
datalcool.mat(:,6:9)=[];
time = (0:1/Fe:(length(datalcool.mat(:,1))-1)/Fe);
delt1 = diff(datalcool.mat(:,5));
deltpos1 = find (delt1>0);
deltatime = time(deltpos1(1));
When I supprime the firt part in the braquetes (i.e.C:Users\Donnes\), the error is in variable G'. When I isert ['G' G' cell2mat(GROUPE(groupe)) '_S' num2str(suj) '_' cell2mat(SESSION(session)) '.mat'] the error in "filename" persist... And I am bloqued in the firt line of the script!
Stephen23
Stephen23 2023 年 10 月 18 日
@Fabiana: yes, that code is not written to be easily modified nor easily understood. Replace the first two lines with this:
P = 'C:\Users\username\MATLAB'; % define the path here
F = 'nameofyourfile.mat'; % define the name here, use SPRINTF if required
datalcool = load(fullfile(P,F));

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


pankhuri kasliwal
pankhuri kasliwal 2019 年 6 月 25 日
Check if your file is in the current folder
dir your_file_name.mat
Sometimes the path problem can happen, in that case use this,
addpath(fullfile('your_path'));
  6 件のコメント
Fabiana
Fabiana 2023 年 10 月 16 日
I can't understand the difference between "added to the matlab path" (because the orientation is Data directories do not need and should not be added to the matlab path.) and "tell it exactly what data files to access" (because the orientation is instead you should simply and reliably tell it exactly what data files to access. Absolute or relative filenames are accepted by all functions that access data files)
Stephen23
Stephen23 2023 年 10 月 28 日
編集済み: Stephen23 2023 年 10 月 29 日
@Fabiana: it is very simple:
  • the MATLAB Search Path is for code. Putting lots of data folders and data files on the Search Path makes MATLAB slow and debugging your code harder.
  • MATLAB functions that import/export data from files accept absolute/relative filenames. Using absolute/relative filenames is efficient and robust. Use FULLFILE if required, e.g.:
P = 'C:\Users\MyName\someFolder'; % absolute or relative filepath
F = 'DataFile.csv'; % filename
T = readtable(fullfile(P,F));
See also:

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


Simenew
Simenew 2023 年 10 月 28 日
clc
clear all
warning off all
close all
% load the absorption spectra
load('absorption_with_plasmon.txt'); % Load the Absorption spectrum with plasmonic effects
load('absorption_without_plasmon.txt'); % Load the Absorption spectrum without plasmonic effects
% Wavelength range
lambda = linspace(350, 700, 50); % Wavelength range in nm
% Interpolate the absorption spectra to match the desired wavelength range
absorption_with_plasmon_interp = interp1(wavelength, absorption_with_plasmon, lambda);
absorption_without_plasmon_interp = interp1(wavelength, absorption_without_plasmon, lambda);
% Calculate the intrinsic absorption enhancement
AE = absorption_with_plasmon_interp ./ absorption_without_plasmon_interp;
% Plot the intrinsic absorption enhancement
figure;
plot(lambda, AE, 'b-', 'LineWidth', 2);
xlabel('Wavelength (nm)');
ylabel('Intrinsic Absorption Enhancement (AE)');
title('Intrinsic Absorption Enhancement in P3HT:PCBM');
grid on;
Abs_enhancement
Error using load
Unable to find file or directory 'absorption_with_plasmon.txt'.
Error in Abs_enhancement (line 2)
load('absorption_with_plasmon.txt'); % Load the Absorption spectrum with plasmonic
  2 件のコメント
Simenew
Simenew 2023 年 10 月 28 日
How can I fixing it?

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

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by