How to make a CSV parser for multiple files with different names?

I am trying to make a parser of multiple CSV files here. Here's a solution for one. This allows me to pick one of the files and work with it. All I want to do with each file is to find the maximum value with respect to other columns. For example, here's the example of output I get:
function upload_btn_Callback(~, ~, handles)
%Uploading a file via user interface
uploaded_file = uigetfile('*.csv','Select a .csv data file');
%If file is loaded
if uploaded_file == 0
set(handles.upload_txt, 'String', 'Status: Cancelled');
else
set(handles.upload_txt, 'String', 'Status: Please wait...');
%Loading the array with CSV-file values
array = csvread(uploaded_file, 8, 0);
set(handles.upload_txt, 'String', ['Uploaded: ' uploaded_file]);
format long;
%Finding all max velocity values
max_vel = max(array(:, 5));
idx = find(array(:, 5) == max_vel);
%Finding time of the max velocity values
t = array(idx(:, 1), 3);
time = num2str(t);
%Finding altitude of the max velocity values
a = array(idx(:,1), 4);
alt = num2str(a);
set(handles.uitable1, 'Visible', 'on');
set(handles.pushbutton2, 'Visible', 'on');
set(handles.uitable1, 'Data', {num2str(max_vel), alt, time});
%This doesn't work...
plot(array(:, 3), array(:, 5));
end
With all this I can't figure out how to make it work for multiple files. Ultimately all I need to do is to pick a directory with those files and load all files with .csv extension, no matter what their names are. I tried different ways with dir() and other stuff but none would work... Maybe there's a better way to do, other than this? I honestly wouldn't even do it in MATLAB if it weren't for its speed with matrices. (Files are hundreds of megabytes big).
Thank you!

답변 (2개)

Walter Roberson
Walter Roberson 2015년 11월 30일

0 개 추천

댓글 수: 1

folder = uigetdir('What folder do you want?');
dirinfo = dir(fullfile(folder, '*.csv'));
for K = 1 : length(dirinfo)
uploaded_file = fullfile(folder, dirinfo(K).name);
array = csvread(uploaded_file, 8, 0);
... etc etc...
end

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

Micard
Micard 2015년 11월 30일

0 개 추천

I have seen that, and this does not help me in my situation. I need to use User Interface to locate a specific folder and use ALL the files in that directory (i.e. I don't want the user to pick all the files manually). In addition, the process described in that example cannot be merged (implemented) with my code, at least not the way I tried.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2015년 11월 30일

댓글:

2015년 11월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by