Concatenation is missing values
Show older comments
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 Comments
Stephen23
on 6 Dec 2018
Guillaume
on 6 Dec 2018
The resulting array is not missing anything that was present in the cells of cellStruct(:, 3). If there was a bug there, you can be sure that it would have been found by now.
So now, we need to understand why you think it does. Can you attach a mat file with that cellStruct cell array?
Personally, I would have written
doubArray = vertcat(cellStruct{:, 3}); %instead of cat(1, ...), produces the same result
so I don't even have to think which way the cells are concatenated. Alternatively, since you're vertically concatenating the rows of a column cell array, you could just do:
doubArray = cell2mat(cellStruct(:, 3));
Neither of these expressions is going to produce a different result from what you already have.
Charles D'Onofrio
on 6 Dec 2018
Guillaume
on 6 Dec 2018
unfortunately, due to the nature of the work I am unable to share the cell array
Well, that's going to be difficult for us to understand the problem. Note that we only need column 3 of the cell array. Since you say that this column only contain numbers, can you just share that?
As a last resort, replace all the numbers by something else. Since the code you've posted does not depend on the actual values, it shouldn't affect the behaviour:
%create a new cell array the same size as cellStruct(:, 3) where each cell contains
%the same type and size of variable but as integers 1 to the number of elements in the variable
testcell = cellfun(@(c) cast(reshape(1:numel(c), size(c)), class(c)), cellStruct(:, 3), 'UniformOutput', false)
Jan
on 6 Dec 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?
Charles D'Onofrio
on 6 Dec 2018
Accepted Answer
More Answers (0)
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!