How to set the output file name same as input names but with an additional word
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jaideep Cherakka Kesavan
am 27 Dez. 2022
Kommentiert: Jaideep Cherakka Kesavan
am 29 Dez. 2022
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.
0 Kommentare
Akzeptierte Antwort
the cyclist
am 27 Dez. 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
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.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!