problem to convert string
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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, ...
0 commentaires
Réponse acceptée
Voss
le 23 Juil 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"
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!