From cell to matrix

3 ビュー (過去 30 日間)
gaetano mallardo
gaetano mallardo 2019 年 6 月 7 日
編集済み: per isakson 2019 年 6 月 8 日
I have a cell variable and need to extract its values.
The cell arrai is like in picture. I would like have a matrix or 3 vectors :
[ 5 6 5 12 6 12 ; 7 11 nan nan nan nan ; 18 19 nan nan nan nan]
(it is not important to have a nan value, i just need to extrcut togheter the informations
function cell2mat doesn't work because of cell dimension

回答 (2 件)

Matt J
Matt J 2019 年 6 月 7 日
編集済み: Matt J 2019 年 6 月 7 日
c( cellfun('isempty',c) ) = {[nan,nan]};
out=cell2mat(c),

per isakson
per isakson 2019 年 6 月 7 日
One way
%%
cac = { [5,6],[5,12],[6,12] ; [7,11],[],[] ; [18,19],[],[] }; % your sample data
ise = cellfun( @isempty, cac );
cac(ise) = {[nan,nan]};
M = cell2mat(cac);
Inspect M
>> M
M =
5 6 5 12 6 12
7 11 NaN NaN NaN NaN
18 19 NaN NaN NaN NaN
>>

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by