Dynamically change .txt file name in MATLAB, COMSOL simulation
Afficher commentaires plus anciens
I have exported code for my COMSOL simulation to MATLAB and I am working on looping through different parameter values for each run of the simulation. At the end of each simulation I need the data to be exported to a file (ideally .csv but it appears I can only do .txt). I need the file name to be updated each time the loop runs.
The problem with the code below is that fname is not recognized as a variable and the file name comes out to be
/Users/marissawhitby/Desktop/C:\Users\jmw\Desktop\Output_Texts\fname
I'm really confused how to do this using COMSOL specific code because I've done similar things in normal MATLAB code in the past.
Any suggestions on how to fix this naming of the .txt file or even how to also get it as a .csv is greatly appreciated.
Note: I've also tried just fname instead of the full file path but that doesn't seem to work either.
Code:
fname = sprintf('Results_E_Field_Iter%d.txt', iter);
model.result.export('data1').set('filename', '/Users/marissawhitby/Desktop/C:\Users\jmw\Desktop\Output_Texts\fname');
model.result.export('data1').set('header', false);
model.result.export('data1').run;
1 commentaire
Rebeka Sultana
le 26 Fév 2022
Hello Marissa,
Is that export command is applicable for each loop iteration? I am working on a problem where the output result is posprocessing of data set (some matrix table) from a nested loop. But I am unable to save/export the table result for each iteration in an allocated path I want. Only the first result is being saved with "model.result.table('tbl1').save('Mutual.csv');" comand. Can you help me find out what I am missing here?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!