accessing tables saved in sequence.
조회 수: 15 (최근 30일)
이전 댓글 표시
Hi,
Please don't suggest fandom page. As I been there already and still have a query. thank you for understanding.
I have ten .csv files with 6 column and 53496 rows, I have read each file from the folder as tables and named each table as t1,t2,...t10. Now I want to create a loop where the loop can access all the 10 tables.
I am trying as t{i}.cloumn1 but this is not working. Can anyone give me any suggestions.
Thank you
댓글 수: 1
Stephen23
2020년 8월 24일
편집: Stephen23
2020년 8월 24일
"I have ten .csv files with 6 column and 53496 rows"
Import them will be easy using a loop, just follow the MATLAB documentation:
"I have read each file from the folder as tables and named each table as t1,t2,...t10"
Numbering variables is not a good approach. Numbering variables like that will make acessing your data slow, complex, buggy, and difficult to debug. The recommended way to import data is to use one variable (e.g. a cell array) and basic indexing.
"Now I want to create a loop where the loop can access all the 10 tables."
If you imported your data using the recommended appraoch then that would be trivial:
"I am trying as t{i}.cloumn1 but this is not working. Can anyone give me any suggestions."
Don't force pseudo-indices into variable names. Import your data into one array using real indices.
답변 (1개)
Mohammad Sami
2020년 8월 24일
편집: Mohammad Sami
2020년 8월 24일
There are a few options. No 1, if all ten files have the same type of data, you can concatenate them into one big table. No 2, store the table in a cell array instead of storing them as individual variables
if true
% assuming 2 files in the folder
alltables = cell(2,1);
Filelist = {'csv1.csv' 'csv2.csv'};
for i=1:length(Filelist)
alltables{i} = readtable(Filelist{i});
end
% access column 1 of tables
Col1tab1 = alltables{1}.Var1;
Col1tab2 = alltables{2}.Var1;
% make one big table
% only work if all tables have same column name and type
Bigtable = vertcat(alltables{:});
Bigtable.Var1;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!