Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How do you pull select columns from dozens of .csv files in a directory and make one long vector with all the values?
1 回表示 (過去 30 日間)
古いコメントを表示
How do you pull select columns from dozens of .csv file in a directory and make one long vector with all the values?
Each .csv file has the required data in the same location.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/373106/image.png)
0 件のコメント
回答 (1 件)
Jon
2020 年 10 月 6 日
編集済み: Jon
2020 年 10 月 6 日
% I'll assume that your files are named follwing some meaningful pattern, e.g. data01.csv, data02.csv, ...You can adapt using your naming convention. You can do something like this:
% define some parameters
numFiles = 3; % just making up an example
baseName = 'data' % modify this according to your naming convention
% preallocate array to hold data
botData = zeros(4,numFiles);
topData = zeros(4,numFiles);
% loop through data
for k = 1:numFiles
% generate the current file name
% e.g. data02, data13,...
filename = [baseName,num2str(k,'%02d'),'.csv']; % modify this according to your naming convention
% read the selected data and save it an array with a column for each
% file
% note row and column ranges are zero referenced cell a1 is 0,0
botData(:,k) = csvread(filename,1,2,[1,2,4,2]);
topData(:,k) = csvread(filename,6,2,[6,2,9,2]);
end
% make single vector of data for bottom and top data
botData = botData(:); % reshapes columwise, could also use reshape(4*numFiles,1)
topData = topData(:);
5 件のコメント
Jon
2020 年 10 月 26 日
Sorry I have been away from the computer for awhile. If you haven't solved this yet I suggest that I think you will need to do the reads in two passes:
botData(1:4,k) = xlsread(filename,1,'C16:C19');
botData(5:8,k) = xlsread(filename,1,'G16:G19');
and similar for the top data.
By rather than using screen shots of your code, you can use the code button on the MATLAB answers menu bar and copy and paste your code in. That way other people can easily copy it back out.
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!