0
如何將字符串文件名包含到fopen函數中?請參閱下面的代碼和評論。MATLAB - 如何將字符串作爲函數的參數
for i=1:5
filename = strcat('Cali',num2str(i));
%first iteration: filename = Cali1
%instead of result.txt there should be Cali1.txt in the following statement, but i want to achieve this by using the string filename
fid = fopen('results.txt', 'wt');
fprintf(fid, 'write something');
fclose(fid);
end
這是[在文檔中明確指出](http://www.mathworks.com/help/matlab/ref/fopen.html#btrnoom-1)。將它作爲參數傳遞給函數。 – excaza
可能還需要添加文件擴展名...'filename = strcat('Cali',num2str(i),'.txt'); ' – RTL
那簡單!謝謝 – d4rty