how to retrieve a table from a cell array?

In the following hierarchy structure of the cell array 'results', assuming that this is a huge set of data tables where we don't know where the table we want for a specific date is located. How can I retrive a certain table from the cell array 'results' that is shown below, using the values in the first column (data file name) of 'results' and the value of the 'Date' variable in the desired table? any idea...
for example:
the cell array results would look like this:
and when expanding a cell from the second column it would look like the image below, where these are the tables that I would like to retrive based on the 'Date' variable (8th column) inside them
and the tables are having the following formats

2 comentarios

Stephen23
Stephen23 el 20 de Sept. de 2021
Editada: Stephen23 el 20 de Sept. de 2021
In general, keeping data together makes it easier to work with.
Although you have spent considerable effort splitting your data up into lots of separate tables, that rather defeats the purpose of using tables (which ultimately is to efficiently group and process data within one array). Most likely this task would be simpler if you just had one table, not hundreds of tables nested in a cell array.
MA
MA el 20 de Sept. de 2021
thanks for your commnet, I agree with you, but this is for the purpose of sorting some data out and it will later on be applied to a huge number of data files. there might be a better way of implementing such thing for sure, but I am a begginer here and I am trying to learn.

Iniciar sesión para comentar.

 Respuesta aceptada

Kevin Holly
Kevin Holly el 20 de Sept. de 2021
The answer is actually written on your tabs.
To view the whole table in the last screenshot, type the following:
results{1,2}{1}

8 comentarios

MA
MA el 20 de Sept. de 2021
Editada: MA el 20 de Sept. de 2021
thank you for your reply, obviously this is true if I know that the table I want to retrieve is located at that for ex: 'results{1,2}{1}'. But this is ment to be a huge set data tables, where I need to search for a specific tables based on the data file name and then the 'Date' variable value. any idea how that can be done?
Kevin Holly
Kevin Holly el 20 de Sept. de 2021
Editada: Kevin Holly el 20 de Sept. de 2021
So, let's assume that you have identified the file you will look at. You then have to identify which tables related to that file has a particular date?
%preallocate variable
Array_of_Tables = ones(length(results{1,2}),1);
for i= 1:length(results{1,2})
%Array of tables with the correct date
Array_of_Tables(i,:) = any(ismember(results{1,2}{i}.Date,'Date you are looking for'))
end
This would give you a logical array of all the tables that have the date.
MA
MA el 20 de Sept. de 2021
Thank you for following up with me. Well, actually a table that we shall retrive is identified uniquely by the variable 'Date', which means there will be only one table coressponding to a specific date. That's why we are using the variable 'Date' to retrieve a desired table.
When using the lines you provided above, I am getting an array of zeros, where there is a table in my data corresponds to that date.
Are your dates saved in table as a numeric array? If so, try this:
%preallocate variable
Array_of_Tables = ones(length(results{1,2}),1);
for i= 1:length(results{1,2})
%Array of tables with the correct date
Array_of_Tables(i,:) = any(ismember(results{1,2}{i}.Date,196612010520))
end
This is what I am using to construct the 'Date' column in my tables
t.Date = datetime(t.YEAR, t.MONTH, t.DAY, t.HOUR, t.MIN, 0, 'Format', 'uuuuMMddHHmm');
this is the error I am getting now
Error using datetime/ismember (line 34)
Comparison is not defined between datetime and double arrays.
Error in thirdtrial (line 45)
Array_of_Tables(i,:) = any(ismember(results{1,2}{i}.Date,196612010520))
and then trying using your lines but still getting the logical array of zeros
Just to be clear, this did not work?
test = datetime(1966,12,01,05,20,0,'Format','uuuuMMddHHmm');
Array_of_Tables(i,:) = any(ismember(results{1,2}{i}.Date,test))
Alternatively, you could try this if your Date is in datetime format within your table:
Array_of_Tables(i,:) = any(ismember(str2num(char(results{1,2}{i}.Date)),196612010520))
MA
MA el 20 de Sept. de 2021
Both of them worked peerfectly as needed. Thank you for your time and your effort.

Iniciar sesión para comentar.

Más respuestas (1)

Sargondjani
Sargondjani el 20 de Sept. de 2021

0 votos

NEver used table but i think this will work:
X = results{1,2}{1,1};
MyDates = X.Date;
Might even work directly:
MyDates = results{1,2}{1,1}.Date

2 comentarios

MA
MA el 20 de Sept. de 2021
thank you for your reply, but the aim is to retrieve the whole table given a specific Date value, not the Date values. and assuming that this is a huge set of data where we don't know where the table we want for a specific date is located.
Sargondjani
Sargondjani el 20 de Sept. de 2021
In that case look at the function: find
Im sure there are many posts about "find a specific value in a matrix"

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Preguntada:

MA
el 20 de Sept. de 2021

Comentada:

MA
el 20 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by