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
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.
fname = sprintf('Results_E_Field_Iter%d.txt', iter);