Borrar filtros
Borrar filtros

How to set the output file name same as input names but with an additional word

7 visualizaciones (últimos 30 días)
I have a few folders each with one .txt file. I load one file at a time using a Matlab GUI:
function load_data_callback(~,~,h)
[FileName, FilePath, FlagUp]=uigetfile({'*.txt'; '*.csv'; '*.xls'; '*.xlsx'; '*.*'}, 'Choose Tab-Delimited Data File');
and make the calculations. Then, the function makes an outputfile called 'NumberOfSpikesPerROI_JCK.csv' by using:
C = ([SeriesLabels;num2cell(SeriesData)]);
writecell(C,'NumberOfSpikesPerROI_JCK.csv')
I want to get the name of the outputfile based on the name of the input file.
For example, if the file name of the first file that I loaded is 'MyFirstFile', then, the output should be 'MyFirstFile_NumberOfSpikesPerROI_JCK.csv' and saved in the same folder (which is currently in Matlab path) as the input file.
Please suggest how to achieve this.
Thank you.

Respuesta aceptada

the cyclist
the cyclist el 27 de Dic. de 2022
If I understand your code correctly, then you've got
FileName = 'MyFirstFile';
So, you could get your new filename as
newFileName = [FileName, '_NumberOfSpikesPerROI_JCK.csv'] % Use square brackets to concatenate character arrays
newFileName = 'MyFirstFile_NumberOfSpikesPerROI_JCK.csv'
It's just a little bit trickier if your input filename is actually something like
FileName = 'MyFirstFile.csv'
and you are trying to insert the text in the middle. But, the principle is the same. Please clarify, if I have misunderstood your question.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by