Find one string within another within all cell of an array

조회 수: 3 (최근 30일)
Arthur Hajaali
Arthur Hajaali 2016년 8월 11일
답변: Pham Dang 2016년 8월 12일
Hello everyone,
I have a table (800*10, this table contain various columns with specific information, in column 8 I have a series of dates each row representing a date of the format dd/mm/yyyy. These dates are not in chronological order and I wish to know of many cells belongs to the month of jan,feb,...,dec. So what I have down so far is load the full file in a table using the readtable function and then I have isolated the column 8 creating a single array (800,1). Finally, I tried to use the srtfind function as explianed in http://uk.mathworks.com/help/matlab/ref/strfind.html, but it is not working... Could anyone help me out please.
Here is the code:
formatspec = '%s%f%f%f%s%s%s%s%s%s';
file_list = readtable('file.txt','Delimiter',',','Format',formatspec);
date_column = file_list(:,3);
jan_cells_location = strfind(date_column,'01/2016');
jan_cells_number = numel(jan_cells);
  댓글 수: 2
Pham Dang
Pham Dang 2016년 8월 11일
Your code is a little bit confused : is date_column the same variable as ships_demo_date ? If true, then, the first problem is strfind does not work on variables of class "table". Could you provide a complete minimal working example ?
You can find more information about extracting data from a table here : Access Data in a Table You will see that have used the "Parentheses" type of indexing. You should consider using the "Dot Indexing" type of indexing.
Arthur Hajaali
Arthur Hajaali 2016년 8월 11일
sorry made a mistake in the code the ship_demo_date should have been date_column I have modified it. And thanks for the info that the function strfind does not apply to class "table". Does that mean that I need to load the file in a array rather a table? Or is it possible for me the extract all the row from the table which contain the segment of string "01/2016". Basically I want the program to extract and tell me the number of cells which containt a day the first month of the year 2016 01/01/2016,...,31/01/2016.

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

답변 (1개)

Pham Dang
Pham Dang 2016년 8월 12일
Please try to replace
date_column = file_list(:,3);
by
date_column = file_list.(3);

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by