Dear matlab users,
I have a structure array, where the majority of fields have identical values. Some differ. The values can be numbers, strings, or cells. See minimal example below for a struct array of size 100, and fields A through F:
length(mystruct) = 100%field A identical number
mystruct(1).A = 5mystruct(2).A = 5...mystruct(100).A = 5%field B identical string
mystruct(1).B = 'hello'mystruct(2).B = 'hello'..mystruct(100).B = 'hello'% field C not identical number
mystruct(1).C = 1mystruct(2).C = 2..mystruct(100).C = 100% field D not identical string
mystruct(1).D = 'x'mystruct(2).D = 'y'..mystruct(100).D = 'z'% field E identical cell
mystruct(1).E = {'a','b'}mystruct(2).E = {'a','b'}..mystruct(100).E = {'a','b'}% field F not identical cell
mystruct(1).F = {'a','b'}mystruct(2).F = {'a','c','d'}..mystruct(100).F = {'b'}
I would like to "flatten" the common values of the structure array (which is actually very large with thousands of fields), and create a cell/vector for the non-common:
length(mystruct) = 1mystruct.A = 5mystruct.B = 'hello'mystruct.C = [1,2,..,100] %this can also be a cell if easier
mystruct.D = {'x','y',..,'z'}mystruct.E = {'a','b'}mystruct.F = {{'a','b'}, {'a','c','d'}, .., {'b'}}
Is there a straight forward way to do this?
Many thanks,
Ida
Best Answer