How to select and read csv data file using uigetfile?

조회 수: 19(최근 30일)
Arshey Dhangekar
Arshey Dhangekar 2021년 10월 5일
댓글: Mathieu NOE 2021년 10월 11일
I want to implement select and read file using uigetfile. How can I implment in my code to read the data?
clear all
T = readtable(T);
  댓글 수: 1
Jan 2021년 10월 6일
warning off is an extremely bad idea. Warnings are essential und useful.
Your code contains an import of the files already. So what exactly is your question?

댓글을 달려면 로그인하십시오.

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 10월 6일
편집: Mathieu NOE 2021년 10월 6일
if you want to grad multiple files with uigetfile, you can do that :
% It is important to grab the files in ascending order
file_list = uigetfile('*.csv', 'Grab the files you want to process', 'MultiSelect', 'on');
if iscell(file_list) == 0
file_list = {file_list};
but I find more efficient to use this , in order to load automatically all files once sorted properly (what matlab is not good at)
how to use it : (example)
%% read multiple files
P = pwd; % currrent directory
S = dir(fullfile(P,'*.csv')); % get list of files in directory
fileNames_sorted = natsortfiles({}); % sort file names into order (
nFiles = numel(fileNames_sorted);
for k = 1:nFiles
F = fullfile(P, fileNames_sorted{k});
S(k).data = csvimport(F); % or READTABLE or whatever.
% Take a look in the structure S: it contains all of your file data and the corresponding filenames, just as you require.
% For example, the 2nd filename and its data:
% Accessing and processing this will be much simpler than messing around with dynamically named variables.

추가 답변(0개)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by