2016-06-27 21 views
0

我有一個循環,並在每次迭代中創建與迭代名稱的目錄,我複製該文件夾內的一些文件和事後我想cd到該文件夾​​,但是當我想cd,我得到的錯誤爲Matlab:如何'cd'(改變目錄)到名爲num2str(#number)的文件夾?

「Error using cd Can not CD to num2str(i)(Name is does not exist or not a directory)。」

我該如何解決這個問題?

parfor i=1:20000 
    iter=num2str(i); 
    mkdir(iter) 
    copyfile('./mainfolder',iter) 
    cd ./num2str(i) 
    [pow_maxx,FFee,AA33,BB33,shape] = main(i); 
    power_max(i,:)=pow_maxx(1,:); 
    Fe(i,:)=FFee; 
    A3(i,:)=AA33; 
    B3(i,:)=BB33; 
    Shape_all(i,:)=shape(1,:); 
end 
+1

'./num2str(i)'是無效的Matlab。嘗試類似'cd(['./'num2str(i)])'(或者可能只是'cd(num2str(i))')。 – horchler

+0

感謝它這樣工作 – Soyol

+0

@horchler我有刪除目錄類似的問題。 1.如何刪除一個名稱爲「num2str(20)'''的數字的目錄,例如。 無的下面的工作: '命令rmdir(num2str(20));'' 命令rmdir( 'num2str(20)');'' 命令rmdir(20);'' 命令rmdir('20' ); ' 2.如何刪除名爲'num2str(20)' – Soyol

回答

0
在你的代碼 cd ./num2str(i)

./num2str(i)不是一個字符串,只需使用cd ['./',num2str(i)]

更重要的是,如果您有一些字符串str1='abc'str2='def',您可以使用[str1,str2]來連接它們。

相關問題