How to Load and Rename a txt File
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I am a Korean university student working on a project using MATLAB GUI. I have a question. If you look at the image below, there are "Load" and "Check" buttons. If you press the "Load" button, you have to load the txt file in any file path. If you press the "Check" button, the loaded txt file must be saved as the file name I specified. I am unable to proceed with this. Please lend me your wisdom. Thank you.
0 Commenti
Risposte (1)
Walter Roberson
il 28 Mag 2022
use uigetfile to get the file name and directory. Check whether the file name variable is numeric: if it is then the user cancelled. Use fullfile() to put the file name and directory together to create a fully qualified file name.
Use uigetfile in a way similar to uigetfile in order to find out where the user wants to write the file.
Use copyfile()
2 Commenti
Walter Roberson
il 28 Mag 2022
basenamein = 'custom.txt';
basenameout = 'Message_Data.txt';
userProfile = getenv('USERPROFILE');
desktop = fullfile(userProfile, 'Desktop') ;
csc = fullfile(userProfile, 'CSC';
infile = fullfile(desktop, basenamein);
outfile = fullfile(csc, basenameout);
copyfile(infile, outfile);
This does not have much of a connection to your original question; it has to worry about where to find the user Desktop, and about where the CSC folder is.
This code to find the desktop is not very robust, as it is common for the user profile to point to Application Roaming, which is not certain to even be on the same disk as the user desktop. The code to reliably find the desktop needs a fair bit of improvement.
.... whereas if you had used uigetfile like I recommend, then the directory returned will be where the file really is, with the user selecting the directory that suits their needs.
Vedere anche
Categorie
Scopri di più su Desktop in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!