How to find text in csv file and filter information the table
17 次查看(过去 30 天)
显示 更早的评论
Hello,
I am in despair about this problem in Matlab I am not progressing in. I am trying to find text in my csv file (I am sorry I cannot post anything from the file but its confidential) and after finding this text, I am trying to filter something from the numbers below it. The numbers can be something like: 0-15, with many digits after the comma. Here is some code I tried myself on:
L = uigetdir('\winfs\EA-proj');
% Identify where to search for files
% Store the name of all .xls files as a vector D
% D = dir([Location, '\*.csv']);
% Extract the file names
filenames = {L(:).name}.';
data = cell(length(L),1);
for ii = length(L):-1:1
% Create the full file name and partial filename
fullname = [Location filesep L(ii).name];
% Read in the data
data{ii} = xlsread(fullname);
end
[~,~,rawData] = xlsread(fullname);
name = 't_kammer';
% look at all row elements in the first column returning
% the first match only
idx = find(strcmp(rawData(:,1),name),1);
if ~isempty(idx)
total = sum(cell2mat(rawData(idx,2:end)));
else
total = 0;
end
If needed, I am working in the 2018R Version
2 个评论
Andrew Janke
2020-1-31
How many digits is "many"? double values are good for about 16 decimal digits of precision.
And what exactly isn't working? You've described what you're doing, but not what you expect to happen and how your actual results are differing.
回答(1 个)
Cris LaPierre
2020-1-31
We don't have enough info really help you code anything. Look into how to access data in a table. You may want to consider using the first column of data as rownames in your table using the ReadRowNames name-value pair.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!