Reading in different files based on a array of strings
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
darova
2020 年 4 月 8 日
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 件のコメント
darova
2020 年 4 月 8 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Standard File Formats についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!