add value to cell array

11 ビュー (過去 30 日間)
michael
michael 2021 年 12 月 29 日
回答済み: Voss 2021 年 12 月 29 日
Hello,
I need to add some values to cell array based on conditions. It can be that on some condition, the value shall be not be added. As I want it to be generic, I use some function that generates the value.
label_text_output = my_function(inputs) % outout is either 'text' or []
label_text{(length(label_text)+1} = label_text_output
If label_text_output = [], then I'm receing
label_text =
'text' []
While I need
label_text =
'text'
at the same conditions.

採用された回答

Stephen23
Stephen23 2021 年 12 月 29 日
編集済み: Stephen23 2021 年 12 月 29 日
if numel(label_text_output)
label_text{end+1} = label_text_output
end
Or alternatively afterwards you could do this:
label_text(cellfun(@isempty,label_text)) = []

その他の回答 (1 件)

Voss
Voss 2021 年 12 月 29 日
It sounds like (I'm not 100% sure) what you want is that when label_text_output is the empty array, it does not get added to the end of label_text. If that's the case, then you can check that label_text_output is not empty before adding:
if ~isempty(label_text_output)
label_text{end+1} = label_text_output;
end

カテゴリ

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

タグ

製品


リリース

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by