Read several large csv and store as separate variables
이전 댓글 표시
I have 26 large .csv files that each take a while to load in to Matlab. I would like to be able to read them all in, using one for loop, so that I can leave the loop to run and work on something else while all of the files import. I would like each to be stored as a separate variable.
I have tried this, but the code fails on the last line where I try to read in the .csv using readmatrix() and store it with a name depending on the file that the loop is currently processing. In this example, I choose to start at the 17th .csv file in the folder as I have inspected the first 16 in a past life :-) The .csv files are 7GB otherwise I would attach an example.
directory=('Y:\SoundTrap\PSD Output');
d=dir(fullfile(directory, '*.csv')); %list all .wav files in path folder
files=length(d);
for i=17:files
disp(d(i).name); %display filename
name=d(i).name;
filename=fullfile(directory, d(i).name);
file(i)=readmatrix(filename);
end
There error I get is:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in checkPSDoutput (line 14)
file(i)=readmatrix(filename);
Thanks for your help!
댓글 수: 3
Rik
2019년 11월 18일
You will probably have to rethink your strategy. Loading several files that large will probably fill your ram before you can do something useful. You also shouldn't dynamically generate file names. You could use a cell array (assuming that fits in your memory).
"You also shouldn't dynamically generate file names"
Probably Rik meant to write that one should not dynamically generate variable names.
"I would like each to be stored as a separate variable."
That would would not be a good way to write your code. You should first read this:
and then use a cell array, just as Star Strider's answer and the MATLAB documentation shows:
Rik
2019년 11월 19일
That was indeed was I meant. Can you still call it a typo if you're using the wrong word?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!