How to retrieve tables from a cell array

조회 수: 2(최근 30일)
MA
MA 2021년 9월 25일
편집: Stephen 2021년 9월 29일
assuming we have some data files and we are storing the data of these files in a cell array called "results", the cell array contains two columns the first is for the name of the file and the second one we have each cell contains multiple tables corresponding to a data file. (see the images below).
Now, assuming that each table of these has a unique "Date" value for the data in it, How can we go through all the cells in the cell array for all the files we have to retrieve the tables that there "Date" value is between for example (196611110928 and 196611110940) or any other values?
I was able to sort this out for having a specific value of the Date, i.e for retrieving a single table, but when having a certain range of the Date values and retrieving multiple tables I am not sure how to do that.. anyone can help?

채택된 답변

Shanmukha Voggu
Shanmukha Voggu 2021년 9월 28일
Hi Osama,
I understood that you want to know
1)how to loop over all cells in the cell array(results)
2)how to loop over all the tables in the cell
According to question I understood that if every row of table has the Date in the specific range for example (196611110928 and 196611110940), then that table can be retrieved
The finalCell is the cell array that contains all the resultant tables
finalCell={};% contains all tables having Date range (196611110928 ,196611110940)
for i=1:size(results,2)% "results" is the cell array mentioned in question
currCell=results{i,2};% current cell in the iteration
for j=1:size(currCell,1)
currTable=currCell{j,1};% current table in the iteration
booleanMatrix=(boolean(ones(size(currTable,1))))';% creating a Boolean matrix that contains all logical 1's
if((currTable.Date>196611110928 & currTable.Date<196611110940)==booleanMatrix)% This condition will true when the Date is in given range
finalCell{end+1}=currTable;% if above condition is true, then add the table to cell array
end
end
end
Note: Before executing following code make sure to have results variable in the workspace.
Refer this for more information.
  댓글 수: 4
Stephen
Stephen 2021년 9월 29일
currTable.Date>196611110928 & currTable.Date<196611110940)==booleanMatrix
% This comparison is completely superfluous ^^
The LE and LT comparisons return TRUE/FALSE values, which the pointless EQ comparison compares against a vector of ONES to return exactly the same TRUE/FALSE values.
Do not learn from such pointlessly obfuscated code.
@Shanmukha Voggu: BOOLEAN is not a MATLAB function, LOGICAL is a MATLAB function. Rather then inventing functions that do not exist it is much more reliable to read the MATLAB documentation.

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

추가 답변(0개)

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by