Function readtable: how to insert the value of a variable double in the directory

조회 수: 6 (최근 30일)
Riccardo
Riccardo 2021년 9월 16일
댓글: Riccardo 2021년 9월 16일
Hi!
For now I have this simple line of code:
iV = readtable("C:\Users\hp\OneDrive\Project\Results\rig53\97\iv\ivdatadir-11\ivdata_up");
and other lines with the same structure for other variables.
I would like to replace the part \rig53\97\ , defining two variables that I can change whenever I want, so that if I need to read data from another directory, for example from "C:\Users\hp\OneDrive\Project\Results\rig55\99\iv\ivdatadir-11\ivdata_up" , I don't have to change the directory everytime, but symply change the value of the variable that I define at the beginning.
I would like to do something like this:
x = 'rig53';
y = 97;
iV = readtable("C:\Users\hp\OneDrive\Project\Results\" num2str(x) "\" num2str(y) "\iv\ivdatadir-11\ivdata_up");
but I don't know what to write in the directory (in the example here, I just wrote a random thing, I know that it doesn't work).
Is there a way to do this?
Thank you!

답변 (2개)

KSSV
KSSV 2021년 9월 16일
f = dir('C:\Users\hp\OneDrive\Project\Results\');
f(3)
f(4)
  댓글 수: 3
KSSV
KSSV 2021년 9월 16일
f = dir('C:\Users\hp\OneDrive\Project\Results\');
T = readtable([f(3).name,filesep,'iv\ivdatadir-11\ivdata_up']) ;

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


Walter Roberson
Walter Roberson 2021년 9월 16일
basedir = fullfile('C:\Users', 'hp', 'OneDrive', 'Project', 'Results');
x = 'rig53';
y = 97;
filename = fullfile(basedir, x, string(y), 'iv', 'ivdatadir-11', 'ivdata_up');
iv = readtable(filename);

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by