Struct contents reference from a non-struct array object

Hi,
I have ds containing cell arrrays (1 by 3571) and each cell index points to a table of 4 by 7 elements. When any cell is empty while concatenating, the above error is shown. Basically, I am trying to access the contents of the cells contained within the cell array "Table" and plot different fields on a 1 by 3571 grid where each index refers to a point on a lat/lon grid.
Here is the code: Any ideas how to fix the error and plot the content of the data set.
for n = 1:3571;
Unc{n}=Table{1,n}.UncA
end;
whos Table
Name Size Bytes Class Attributes
Table 1x3571 9326972 cell
Here is the sample content of one of the cells contained in teh cell array.
Var A UncA B UncB C UncC
'1' -0.0186917327837646 -0.0266242514128150 0.00420612704074986 -0.00200002085968102 0.107411895593770 0.0187751225715014
'2' -0.0141854422900873 -0.0316765707830826 0.00382987363234866 -0.00237934723997174 0.0345770815773565 0.0224174109442981
'3' -0.0180850135958575 -0.0258819602652245 0.00416311313467285 -0.00194411629488122 NaN NaN
'4' -0.0167188467826965 -0.0315984164923636 0.00407529091905538 -0.00236624020568344 NaN NaN

 Respuesta aceptada

Greg
Greg el 28 de Nov. de 2018
Editada: Greg el 29 de Nov. de 2018
If I'm understanding correctly, some indices of your cell array contain tables, and others are empty? What do you want to happen with the empty cells?
blnEmptyCells = cellfun(@isempty,Table);
%%% If throwing them out isn't ok, see additional posts below
Table(blnEmptyCells) = [];
Unc = cell(length(Table),1);
for ij = 1:length(Table)
Unc{ij} = Table{1,ij}.UncA;
end

5 comentarios

skanwal
skanwal el 28 de Nov. de 2018
Editada: skanwal el 28 de Nov. de 2018
Hi Greg,
This code work but deletes the cells with empty values []. I do not want to delete these values becuase i will lose the index values to lat/lon and won't be able to know the location of these points. So, I applied this function to replace the empty cells with NaN:
ds(cellfun(@isempty, ds)) = {nan}
But in this case, it gives me the same error I mentioned above
Greg
Greg el 29 de Nov. de 2018
blnEmptyCells = cellfun(@isempty,Table);
Unc = num2cell(nan(length(Table),1));
for ij = 1:length(Table)
if blnEmptyCells(ij)
continue;
end
Unc{ij} = Table{1,ij}.UncA;
end
Greg
Greg el 29 de Nov. de 2018
Your original error message is quite clear: you're trying to treat a non-structure as a struct (in later releases the message changes to "dot indexing is not available for this data type"). You can't do Table{1,ij}.UncA if Table{1,ij} = nan. The nan is a double, not a struct, and has no dot indexing ability. You could put a fake struct in Table{1,ij} to "make your code work as is," but that isn't the right solution. The better answer is to use simple isempty checking (see post above) and skip the dot-indexing entirely.
Thank you Greg. That has solved the problem now. I have the same no of cells in the output as in the original data set.
Greg
Greg el 29 de Nov. de 2018
Happy to help!

Iniciar sesión para comentar.

Más respuestas (1)

skanwal
skanwal el 29 de Nov. de 2018
From the origical data (1 by 3071), I have the indices for both the empty and non-empty cells. is there any way that I can fill the newly generated cells array which is 1 by 2076 cell array (with empty cells removed ) with elements such as empty cells or NaN based on the indices in MATLAB where there were empty cells in the original data to keep the dimensions of the data same?

Categorías

Productos

Versión

R2017a

Preguntada:

el 28 de Nov. de 2018

Comentada:

el 29 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by