Read multiple data from text files and storing the full data in different variables to carry tasks later individually.
3 次查看(过去 30 天)
显示 更早的评论
I would like to read multilple files with UIGETFILE command and then read any number of text files ( sample data attached). It should read the data and store it in variables which will be equal to the number of files. The variable should contain the full data from the text file ( in table format or any form which I could carry calculations with different rows and columns)
I have used this code ( but the variable is just showing path and file name, not the data inside it.)
[filename,pathname] = uigetfile('.txt', 'Select the types of fuel to be compare','Multiselect','on');
if iscell(filename)== 0
filename = {filename};
end
numfiles = size(filename,2);
for ii = 1:numfiles
filename{ii};
entirefile{ii} =fullfile(pathname,filename{ii});
fid = fopen(entirefile{ii});
% your code
fclose(fid);
end
0 个评论
回答(1 个)
Arpit Bhatia
2020-10-29
Hi Amanullah,
The fullfile function is only building the complete path to the selected text files and does not return the contents of the files. To read the data inside the text files, use the fileread function as show below.
entirefile{ii} = fileread(fullfile(pathname,filename{ii}));
Using fileread does not require you to use the fopen and fclose functions and hence those lines should be deleted.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!