Reading file in subfolders with readtable

조회 수: 34 (최근 30일)
mehtap agirsoy
mehtap agirsoy 2021년 6월 29일
댓글: mehtap agirsoy 2021년 6월 29일
Hi guys,
I need to run my code in the mainfolder "Rainbow" which has 5 different subfolders. Each subfolder contains .xls files and .dat files. For each loop code needs to read related .xls files and make some calculations with the .dat files. When I run the code in the Rainbow folder I got this:
Error using readtable (line 245)
Unable to find or open 'M1_Normal_T1.xls'. Check the path and filename or file permissions.
Error in Rainbow_analysis (line 17)
DAT = readtable((fname), 'VariableNamingRule', 'preserve' );
My path and filename:
fname = 'M1_Normal_T1.xls'
pname ='/Users/mehtap/Documents/MATLAB/Rainbow/M1_Normal_T1/'
When I copy the code in one of the subfolders it runs but this time doesn't read the .dat files in the other subfolders just use the ones inside it. I should run the code in the Rainbow folder but always I received error. I really got stuck this single line. Could you please help? Thanks in advance.

채택된 답변

Mohammad Sami
Mohammad Sami 2021년 6월 29일
use the function fullfile to get the fullpath to the file.
fullpath = fullfile(pname,fname);
DAT = readtable(fullpath, 'VariableNamingRule', 'preserve' );
  댓글 수: 1
mehtap agirsoy
mehtap agirsoy 2021년 6월 29일
Many thanks Mohammad, really appreciate it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by