put number in cell

3 次查看(过去 30 天)
NA
NA 2019-5-24
A={[21],[],[32],[4],[60],[]};
length_A = cellfun(@(m) length(m),A,'uni',0);
B= cell(1, size(A,2));
B(cell2mat(length_A)) = 0.2;
'A' has empty elements, I want to put empty elements as 0 in B. For other element it should be 0.2
I want to have this result
B={[0.2],[0],[0.2],[0.2],[0.2],[0]};

采纳的回答

madhan ravi
madhan ravi 2019-5-24
编辑:madhan ravi 2019-5-24
B = num2cell(~cellfun('isempty',A) * .2)

更多回答(1 个)

Catalytic
Catalytic 2019-5-24
编辑:Catalytic 2019-5-24
B=~cellfun('isempty',A)*0.2

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by