General
Follow


Import csv files from folder

Shogo on 5 Aug 2020
Latest activity Edit by Jiro Doke on 21 Aug 2020

help

Thank you for your helping. I'm trying to import csv files form a folder, however it does not work.

The following code might be wrong.. fname=mtlb_dir('Users/shogo/Left_Leg_Single-Leg_Landing/SLLExport/*.exp')

I appreciate it if you help,

Sincerely, Shogo

Sebastian Gross
Sebastian Gross on 5 Aug 2020

Hi Shogo,

if you right-click on one of your files in the current folder browser window in MATLAB and select 'Import Data', MATLAB will open a convenient Import App for you. Here, you can chose the output format, the variables and other import parameters.

Instead of pressing 'Import Selection', you select the small arrow next to it and press 'Generate Function' (or 'Generate (Live) Script' depending on your liking). This will give you code that will import your data.

This code will need some tweaking in case your files have different lengths. Also, you will want to put a loop around it so you open every file in your directory. However, this is a great start and it will help you define your output formats easily.

I hope this helps.

Shogo
Shogo on 18 Aug 2020

Dear Sebastian Gross,

Thank you for your replying! Your precious advice did work! I appreciate it you.

I am currently struggling with how to extract the number of rows in the second wave of data with two waves, such as columns B and C of the sample data, for the following two points. (1) The value in column C increases in value from 0 to 0 and then to 0 again. Then, the number of rows at the beginning of the second wave appears. Specifically, the number of lines at the moment it goes from 0 to 10 or more. (2) The number of rows where the minimum value appeared when the second wave in column B came in. I struggled with the Min and find functions, but I couldn't do it, so if you have any other methods, I'd appreciate it if you could help me out.

Sincerely, Shogo

Sebastian Gross
Sebastian Gross on 20 Aug 2020 (Edited on 21 Aug 2020)

Hi Shogo,

I am not sure I understood what you are looking for. But this code identifies the waves.

I hope this helps.

Sebastian

--

data = readtable('sample file.xlsx');
mask = data{:,3} > 0;
mask_count = bwlabel(mask);
for i = 1:max(mask_count)
    disp(['*** Wave ' num2str(i)]);
    wave = data(mask_count==i,:);
    disp(['Length: ' num2str(size(wave,1))]);
    disp(['Frist entry: ' num2str(find(mask_count==i,1,'first'))]);
    disp(['Last entry: ' num2str(find(mask_count==i,1,'last'))]);
end

Output for your file:

* Wave 1

Length: 900

Frist entry: 5094

Last entry: 5993

* Wave 2

Length: 3123

Frist entry: 6671

Last entry: 9793