Error using ls - no such file or directory

조회 수: 7 (최근 30일)
Suad Vejselovski
Suad Vejselovski 2022년 3월 11일
편집: Stephen23 2022년 4월 26일
Im trying to run a script i recived from my Professor. Hi showed me how to lunch it. He runs matlab on windows. I have a mac M1 with BigSur.
He told me just to add in the line of the "path" and the line of "pathres" my folder path to the file i want to examine with the script and the path where i want to save the results.
This is the beginnin of the script.
clear
close all
path = '/Users/suadvejselovski/Docu/MATLAB/Matlab_work/Dafare';
pathres = '/Users/suadvejselovski/Docu/MATLAB/Matlab_work/AnalizzatiSuad';
filelist = ls ([path '*.csv']);
analized_rawdata = {};
analized_data = {};
this is the error:
Error using ls (line 47)
ls: /Users/suadvejselovski/Docu/MATLAB/Matlab_work/Dafare*.csv: No such file or directory
Error in lookDataSegments (line 6)
filelist = ls ([path '*.csv']);
  댓글 수: 1
Stephen23
Stephen23 2022년 3월 12일
편집: Stephen23 2022년 4월 26일
Do NOT just add slashes yourself!
The correct approach is to use FULLFILE, which will automatically use the correct file separator character for your OS:
Using the output from DIR is generally easier than using the output from LS.

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2022년 3월 11일
Use fullfile() and do NOT use path as the name of your variable:
folder = '/Users/suadvejselovski/Docu/MATLAB/Matlab_work/Dafare';
if ~isfolder(folder)
errorMessage = sprintf('Error: folder does not exist:\n%s', folder);
uiwait(errordlg(errorMessage));
return;
end
filePattern = fullfile(folder, '*.csv')'
filelist = ls(filePattern);

Cris LaPierre
Cris LaPierre 2022년 3월 11일
Add one more forward slash to terminate your variable path
path = '/Users/suadvejselovski/Docu/MATLAB/Matlab_work/Dafare/';
% ^ added here
filelist = ls ([path '*.csv']);
  댓글 수: 2
Suad Vejselovski
Suad Vejselovski 2022년 3월 11일
thanks the error is solved but i have a new error now:
>> lookDataSegments
Error using importdata (line 139)
Unable to open file.
Error in lookDataSegments (line 17)
data = importdata([path filename]);
what i have to do ?
Cris LaPierre
Cris LaPierre 2022년 3월 11일
편집: Cris LaPierre 2022년 3월 11일
Can you open the file in MATLAB manually? If so, inspect the result of your concatenation:
[path filename]
Is it correct?
Also +1 to image analyst's comment to use fullfile instead.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by