Iteratively rename a .txt using writematrix

조회 수: 3 (최근 30일)
Richard Wood
Richard Wood 2021년 7월 18일
편집: Simon Chan 2021년 7월 18일
Hello everybody,
I have created the following array:
substrates={'MgO' 'SiO2' 'W' 'Al2O3' 'Sapphire'};
What I want to do is, after calculating an array within a for loop for each "substrates" element, i=1:length(substrates), save it in .txt using the writematrix function. I have tried something like:
writematrix(matrix,'C:\Users\...\Matrix_',substrates{i},'_Substrate.txt','Delimiter','space')
But it doesn't work, telling me the error that "MgO" is an invalid parameter name.
Any ideas?

채택된 답변

Simon Chan
Simon Chan 2021년 7월 18일
편집: Simon Chan 2021년 7월 18일
If you would like to write into a file with path and name as 'C:\Users\...\Matrix_MgO_Substrate.txt',
you need to concatenate strings horizontally like this:
writematrix(matrix,strcat('C:\Users\...\Matrix_',substrates{i},'_Substrate.txt'),'Delimiter','space')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by