How to set the output file name same as input names but with an additional word
7 views (last 30 days)
Show older comments
Jaideep Cherakka Kesavan
on 27 Dec 2022
Commented: Jaideep Cherakka Kesavan
on 29 Dec 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 Comments
Accepted Answer
the cyclist
on 27 Dec 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 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!