cell to matrix with numerical and logical values

2 Ansichten (letzte 30 Tage)
Elie Elias
Elie Elias am 7 Nov. 2018
Beantwortet: Stephen23 am 7 Nov. 2018
i have a cell array with numerical values and logical values and i want to transform it to a matrix with only numerical values. How can i do that? Thanks

Antworten (2)

Star Strider
Star Strider am 7 Nov. 2018
Try this:
C = {1:5, (1:6)>3}; % Create Cell Array
N = cell2mat(C(cellfun(@isnumeric,C))) % Desired Output
Note — The numeric elements of your cell array must have the correct dimensions, or the cell2mat call will throw a error for mismatched dimensions when it tries to concatenate them.

Stephen23
Stephen23 am 7 Nov. 2018
Where each cell contains a scalar numeric or logical:
cell2mat(cellfun(@double,C))

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by