Save file with same name but different folder

조회 수: 1 (최근 30일)
Nicolas
Nicolas 2011년 4월 11일
Hi,
I have a selection of files that i would like to change, then save these files with the same name but in a different folder.
list_files2load = ls('*.txt');
[m,n] =size(list_files2load);
for j=1:m
sprintf('loading file : %s',list_files2load(j,:))
s=load(list_files2load(j,:));
s(:,7)=s(:,7).*pi;
s(:,8)=s(:,8).*pi;
I'm changing two columns of 's' and i want to save this file with the same name (the one in list_files2load(j,:)) but in a different folder.
i didn't manage using the save command..
so I welcome any advice!
Cheers,
n.

채택된 답변

Jan
Jan 2011년 4월 11일
Using the LS command and catching the CHAR array output is not stable, because it kills trailing spaces. Better:
list_files2load = dir('*.txt');
files = {list_files2load.name};
m = length(files);
for j=1:m
sprintf('loading file : %s', files{j})
s = load(files{j});
s(:,7)=s(:,7).*pi;
s(:,8)=s(:,8).*pi;
save(fullfile('D:\Temp\', files{j}), 's');
end
  댓글 수: 1
Nicolas
Nicolas 2011년 4월 12일
Thanks a lot
the fullfile works better like that for me !
save(fullfile('C:','Users','nlec002','Desktop','Data shape 1Hz','data', files{j}), 's','-ASCII')
cheers

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by