problem to convert string
조회 수: 26 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!