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 CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by