Copyfile with variable in the pathname

조회 수: 3 (최근 30일)
Marc-André Lemieux
Marc-André Lemieux 2012년 1월 24일
댓글: Walter Roberson 2020년 4월 7일
Hi,
I want to copy some file but the path were they are going has a variable in its name
ex:
for compteur=1:1 nomaccel=fscanf(fidacc2,'%s',1); % read the name of the folder in a file
copyfile('LireDonneesDH.m','..\nomaccel\','f') %nomaccel is the variable copyfile('CompterLigne.m','..\nomaccel\','f') copyfile('GraphiqueDH.m','..\nomaccel\','f') cd (nomaccel); run GraphiqueDH cd .. end
So Matlab needs to understand that nomaccel is a variable.
I'm not sure how to do this
Thx for helping me !

답변 (2개)

Walter Roberson
Walter Roberson 2012년 1월 24일

Polop Pilipi
Polop Pilipi 2020년 4월 7일
편집: Polop Pilipi 2020년 4월 7일
Hello french fellow, you may be old now but for people coming on this page i would like to try an answer :
I would define first the path with dynamic strings :
destination_file_name = fscanf(fidacc2,'%s',1); % read the name of the folder in a file
destination_file_path = ([ '..\' , destination_file_name , '\' ]) %which gives > destination_file_path = '..\destination_file_name\'
%if you want to use numbers in the file name, you can also use 'num2str' function in the destination_file_path variable
copyfile('LireDonneesDH.m',destination_file_path,'f')
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 4월 7일
We recommend using fullfile() instead of concating together directories as character vectors.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by