How to create a matrix from csv files?
3 次查看(过去 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!