How to retrieve tables from a cell array

6 visualizaciones (últimos 30 días)
MA
MA el 25 de Sept. de 2021
Comentada: Hailey Hayes el 15 de Jul. de 2022
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?

Respuesta aceptada

Shanmukha Voggu
Shanmukha Voggu el 28 de Sept. de 2021
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.
  5 comentarios
Stephen23
Stephen23 el 29 de Sept. de 2021
Editada: Stephen23 el 29 de Sept. de 2021
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.
Hailey Hayes
Hailey Hayes el 15 de Jul. de 2022
I have a similar use case. I used this to help sort my tables and now I need to take a time difference within the sorted tables. The sorted tables are in their own cell array. Is there a way to perform subtraction on multiple tables within a cell array using a for loop?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by