필터 지우기
필터 지우기

How to find text in csv file and filter information the table

조회 수: 14 (최근 30일)
Black4Ghost
Black4Ghost 2020년 1월 12일
댓글: Black4Ghost 2020년 2월 3일
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
Meg Noah
Meg Noah 2020년 1월 12일
Can you read your file using
readtable
into a table?
Andrew Janke
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
Cris LaPierre 2020년 1월 31일
I'll second Meg Noah. Don't use xlsread on a csv file. Try readtable.
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.
  댓글 수: 1
Black4Ghost
Black4Ghost 2020년 2월 3일
Here is the working code I created if anybody needs it. It is only a fragment and not everything but its the part I asked for in this question.
function checkbox1_Callback()
h_push1 = findobj( 'Style', 'pushbutton',...
'String', 'Ordner Auswählen', 'Tag', 'pushbutton1' );
userdata_push = get( h_push1, 'UserData' );
filenames = {userdata_push.filelist(:).name};
flagInRange = false( 1, length( filenames ) );
for ii = length( filenames ):-1:1
fullname = [userdata_push.directory filesep userdata_push.filelist(ii).name];
[num, txt] = xlsread( fullname );
header = txt( 1,: );
header_flag = strcmp( header, 'Searched for String' );
counter = 1:1:length( header_flag );
counter = counter .* header_flag;
column_index = sum( counter );
column_number = num( :, column_index );
lower_limit = ( column_number >= 'Number you searching for' );
upper_limit = ( column_number <= 'Number you searching for' );
check_limit = double( lower_limit ) + double(upper_limit);
check_limit = (check_limit == 2);
if sum( check_limit ) > 0
flagInRange(ii) = true;
end
end
set( gcbo, 'UserData', flagInRange );
disp('Searching completed');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by