How can I convert variable size cell structure to column or row data?

7 views (last 30 days)
Hello
As same structure I attached the "RawCellData", I have a 1x29 cell matrix. And each cell matrix has a variable number of column elements.
What I want to achieve is to turn all the elements into a single cell matrix of 1xN or Nx1 as I added in "DesiredColumn"
How can I do this with a for loop?
By the way, I am trying to check whether there are certain blocks used in the simulink model and how many of them I have obtained as raw data. So matrix element count depends on simulink model. The column matrix will be used to prepare a Check rule to Model Advisor
Thanks in advance

Accepted Answer

Stephen23
Stephen23 on 18 Dec 2023
C = load('RawCellData.mat').ForbBlocks
C = 1×5 cell array
{0×1 cell} {3×1 cell} {1×1 cell} {2×1 cell} {0×0 double}
D = load('DesiredColumn.mat').DesiredRow
D = 8×1 cell array
{0×0 double } {'Forbidden/Subsystem1/Subsystem/Descriptor State-Space' } {'Forbidden/Subsystem2/Subsystem/Descriptor State-Space' } {'Forbidden/Subsystem2/Subsystem/Descriptor State-Space1'} {'Forbidden/Subsystem1/Subsystem/EntityTransport Delay' } {'Forbidden/Subsystem1/Subsystem/First Order Hold' } {'Forbidden/Subsystem2/Subsystem/First Order Hold' } {0×0 double }
C(cellfun(@isempty,C)) = {{[]}};
E = vertcat(C{:})
E = 8×1 cell array
{0×0 double } {'Forbidden/Subsystem1/Subsystem/Descriptor State-Space' } {'Forbidden/Subsystem2/Subsystem/Descriptor State-Space' } {'Forbidden/Subsystem2/Subsystem/Descriptor State-Space1'} {'Forbidden/Subsystem1/Subsystem/Entity↵Transport Delay' } {'Forbidden/Subsystem1/Subsystem/First Order Hold' } {'Forbidden/Subsystem2/Subsystem/First Order Hold' } {0×0 double }

More Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!