Filter löschen
Filter löschen

problem to convert string

16 Ansichten (letzte 30 Tage)
aldo
aldo am 23 Jul. 2023
Beantwortet: Voss am 23 Jul. 2023
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, ...

Akzeptierte Antwort

Voss
Voss am 23 Jul. 2023
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"

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by