How to create a matrix from csv files?
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I have a text matrix with my file names called log_files
log_files = ['file1.csv';'file2.csv';'file3.csv';'file1.csv';'file1.csv';'file4.csv']
I also have a matrix with the data of each csv files, called datafiles
datafiles = [1 1 1;2 2 2;3 3 3;4 4 4]
Where [1 1 1] is the data in file1.csv, [2 2 2] is the data in file2.csv, [3 3 3] is the data in file3.csv and [4 4 4] is the data in file4.csv
What I want, is a matrix called log_data that would look like this (according to log_files)
log_data= [1 1 1;2 2 2;3 3 3;1 1 1;1 1 1;4 4 4]
Thank you for the help you will provide.
댓글 수: 1
Rik
2019년 11월 29일
Do you really have a char array? Or is it actually a cell array with the file names?
You can use a loop to read each file and store them in a matrix. What have you tried so far?
답변 (2개)
Walter Roberson
2019년 11월 29일
filenames = {'file1.csv', 'file2.csv', 'file3.csv', 'file4.csv'};
log_files = {'file1.csv';'file2.csv';'file3.csv';'file1.csv';'file1.csv';'file4.csv'};
[~, idx] = ismember(log_files, filenames);
log_data = datafiles(idx,:);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!