Concatenation is missing values
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Charles D'Onofrio
il 6 Dic 2018
Commentato: Stephen23
il 26 Set 2025 alle 10:38
I am using the command:
doubArray = cat(1,cellStruct{:,3});
to extract an array of numeric values from a cell structure of mixed variable types. All of the variables in column 3 of the cell structure are of data type “double“.
The resulting array is missing 33 of the 116397 expected entires. The missing 33 entries are from a variety of locations within the cell structure and there does not appear to be any rhyme or reason behind which entries are missing.
Has anyone encountered this problem before and know of a solution?
7 Commenti
Jan
il 6 Dic 2018
"The resulting array is missing 33 of the 116397 expected entires."
The cat command does not ignore values. Therefore I assume that the expectation of 116397 elements is the actual problem. Why do you assume this amount of data? How do you determine, which elements are missing? What does this reply:
S = sum(cellfun('prodofsize', cellStruct(:,3)))
This is the number of elements of all arrays contained in the 3rd column of cellStruct - by the way: isn't the part "Struct" in the name confusing here?
Risposta accettata
Stephen23
il 6 Dic 2018
Modificato: Stephen23
il 6 Dic 2018
33 of the cells in the third column contain empty arrays:
>> find(cellfun('isempty',cellStruct(:,3)))
ans =
21968
21969
27848
35808
43424
52648
52649
52650
52651
52652
52653
52654
52655
60284
60285
60286
60287
60288
60289
60290
60291
60292
60293
60294
60295
60296
60297
60298
60299
65762
65763
65839
65840
While the rest of the cells in the third column apparently have one row:
>> find(cellfun('size',cellStruct(:,3),1)>1)
ans = []
In any case, the total number of rows in all of the cells in the third colum is:
>> sum(cellfun('size',cellStruct(:,3),1))
ans = 116364
And that is the exact number of rows that your numeric array contains:
>> size(doubArray,1)
ans = 116364
So far nothing suggests that any data has gone "missing" when concatenating those cell contents.
4 Commenti
Tjeerd
il 26 Set 2025 alle 9:01
I have a similar problem in that NaNs are excluded in the concatenated array. Is there a way to include them, such that the answer in your example would be:
1 2 3
nan nan nan
4 5 6
Stephen23
il 26 Set 2025 alle 10:38
"I have a similar problem in that NaNs are excluded in the concatenated array."
None of the concatenation operators "exclude" NaN values. Lets try them all right now:
[1:3;nan(1,3);4:6]
vertcat(1:3,nan(1,3),4:6)
horzcat(1:3,nan(1,3),4:6)
I do not see any values being "excluded".
"Is there a way to include them.."
Yes, you include the NaNs in the arrays being concatenated.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!