How can I loop my CSV reader?

4 次查看(过去 30 天)
onamaewa
onamaewa 2018-11-9
My files are in 1 folder which I set in Matlab as my Current Folder. The names are: g1, g2, g3, g4, g5, g6, and so on...
Currently, I'm importing using the code below.
h1 = csvread('g1.csv', 9, 0, [9, 0, 10008, 8]);
h2 = csvread('g2.csv', 9, 0, [9, 0, 10008, 8]);
h3 = csvread('g3.csv', 9, 0, [9, 0, 10008, 8]);
h4 = csvread('g4.csv', 9, 0, [9, 0, 10008, 8]);
h5 = csvread('g5.csv', 9, 0, [9, 0, 10008, 8]);
h6 = csvread('g6.csv', 9, 0, [9, 0, 10008, 8]);...
It works, but I know there has to be a way to loop this function. Any ideas on a simple for-loop to complete this task?
  1 个评论
onamaewa
onamaewa 2018-11-10
I'm trying to do something like this.
for (i = 1:10)
csvread('g(i).csv', 9, 0, [9, 0, 10008, 8])
end

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2018-11-9
There are two ways there depending on what order you want to sort them in and if any files are missing.
  2 个评论
onamaewa
onamaewa 2018-11-10
I read the link, but can't follow. I'd like to do something like this:
for (i = 1:10)
csvread('g(i).csv', 9, 0, [9, 0, 10008, 8])
end
Walter Roberson
Walter Roberson 2018-11-10
Well you can't. You have to use techniques such as are described at the link that was posted.
for (i = 1:10)
csvread( sprintf('g(%d).csv', i), 9, 0, [9, 0, 10008, 8])
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by