Reading in different files based on a array of strings
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to create a app with the app designer program that lets the user obtain info from different files depending on some inputs given. I am having trouble getting the files to read in, as i want to list each file name as part of an array and then be able to choose which filename to read. Here's an example of test code I'm using.
Any ideas on how to do this?
Contact = ['C1.txt','C2.txt']; %this is the array of strings that i am using for the names of each file. It will be longer than 2 files
text = fileread(Contact(1)) %this gives me the output I want if I put the filename directly in here, but not if I try to read it from the array.
0 commentaires
Réponse acceptée
darova
le 8 Avr 2020
Use this simple construction
Contact = {'C1.txt','C2.txt'}; %this is the array of strings that i am using for the names of each file. It will be longer than 2 files
for i = 1:length(Contact)
text = fileread(Contact{i}); %this gives me the output I want if I put the filename directly in here, but not if I try to read it from the array.
end
4 commentaires
darova
le 8 Avr 2020
Try this
Contact = {'C1.txt','C2.txt'}; %this is the array of strings that i am using for the names of each file. It will be longer than 2 files
for i = 1:length(Contact)
fname = ['Contact\' Contact{i}];
text = fileread(fname); %this gives me the output I want if I put the filename directly in here, but not if I try to read it from the array.
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!