Help naming text file according to user input
Show older comments
Hello everyone,
I am trying to create a text file (using a gui), and I would like the name of the file to match what the user inputs in an edit text box. At first, I am trying to use a simple script (attached below) to see if I can accomplish this, but I am unable to create the .txt file. The file being created is just a "file". What would be the best way to approach this? Am I on the right track?
Thank you in advance for any help provided.
Code:
prompt = 'Please enter the file name: ';
fileName = input(prompt,'s');
% open a file for writing
fid = fopen(fileName, 'wt');
if fid == -1
error('Cannot open file: %s', fileName);
end
Accepted Answer
More Answers (1)
Sowndarya Sivalingam
on 2 Jun 2020
0 votes
I want to know how to crete this script: Write a matlab script which will take input for a file name from the command prompt. The script will also contain a function. The function will be called with file name, it will extract the data part, calculate the size of the data, average of the data, maximum value in the data and report back those values to main function.
1 Comment
KAE
on 30 Apr 2024
Post this as a new question and include what you have tried so far.
Categories
Find more on Data Import and Analysis 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!