how assign cell to dropdown menu

9 ビュー (過去 30 日間)
shamal
shamal 2025 年 1 月 19 日
回答済み: Avni Agrawal 2025 年 1 月 20 日
app.PeriodicityDropDown.Items
ans =
1×4 cell array
{'Option 1'} {'Option 2'} {'Option 3'} {'Option 4'}
K>> class(tmp)
ans =
'double'
i try this solution:
K>> app.PeriodicityDropDown.Items={tmp}
'Items' must be a 1-by-N cell array of character vectors or a string array.
K>> app.PeriodicityDropDown.Items=num2cell(tmp)
'Items' must be a 1-by-N cell array of character vectors or a string array.
how can i assign it?
  1 件のコメント
Stephen23
Stephen23 2025 年 1 月 20 日
Did you try converting the numeric to a string array or to a cell array of character vectors?

サインインしてコメントする。

採用された回答

Avni Agrawal
Avni Agrawal 2025 年 1 月 20 日
Hi Luca,
I understand that you are trying to set the Items property of a dropdown component in a MATLAB app with numerical values, but the dropdown requires a cell array of character vectors or a string array.
Here is how you can convert your numerical array to a suitable format:
1. Convert the numerical array to a cell array of character vectors:
%If tmp is your numerical array, you can convert it to strings first and then to a cell array:
tmp = [1, 2, 3, 4]; % Example numerical array
tmpStr = arrayfun(@num2str, tmp, 'UniformOutput', false);
app.PeriodicityDropDown.Items = tmpStr;
2. Convert the numerical array to a string array:
%Alternatively, you can convert the numerical array directly to a string array:
tmp = [1, 2, 3, 4]; % Example numerical array
tmpStrArray = string(tmp);
app.PeriodicityDropDown.Items = tmpStrArray;
I hope this helps!

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by