フィルターのクリア

problem to convert string

16 ビュー (過去 30 日間)
aldo
aldo 2023 年 7 月 23 日
回答済み: Voss 2023 年 7 月 23 日
hi, i try use:
num2str(app.UITable.Data(:,15))
{app.UITable.Data(:,15)}
d=str2double(app.UITable.Data(:,15))
i receive always error
disp(app.UITable.Data(:,15));
d=str2double(app.UITable.Data(:,15)); %%trovo i "selezionati"
sel=find(d==1);
app.UITable.Data(sel,4)= string(app.Trading(2)); %gli assegno il valore "from strategy"
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
Unable to perform assignment because value of type 'string' is not convertible to 'cell'.
Error in PredatorManageStrategie/OnFullMenuSelected (line 249)
app.UITable.Data(sel,4)= string(app.Trading(2)); %gli assegno il valore "from strategy"
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...

採用された回答

Voss
Voss 2023 年 7 月 23 日
I assume that the cell array of numeric 1's shown in the question is the result of the disp(app.UITable.Data(:,15)); line, and that what we see there is the whole column 15.
In that case, it's doesn't make sense to do str2double on app.UITable.Data(:,15) since it already contains numeric data (and not character arrays or strings).
Instead, concatenate the contents of the cells of column 15 together into the numeric vector d and find where d == 1:
d = [app.UITable.Data{:,15}]; %%trovo i "selezionati"
sel = find(d == 1);
Then set the corresponding cells in column 4 to app.Trading(2), converted to a string and wrapped in {} to make it a scalar cell array to match the type of app.UITable.Data, which is also a cell array:
app.UITable.Data(sel,4) = {string(app.Trading(2))}; %gli assegno il valore "from strategy"

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by