function startupFcn(app, setting)
app.Calling_Predy2=settings;
app.UITable.ColumnName=["Strategy";"On";"Underlying";"Trading";"OOS";"Sipp.source";"Slippage";"Type";"Horizon";"Filter skip";"Static Size";"Min Size";"Max Size";"Min AvgTrade";"Select"];
app.UITable.ColumnEditable=[false,true,false,true,true,true,true,true,true,true,true,true,true,true,true];
cat = categories(app.Trading);cat2=categories(app.SlippSource);cat3=categories(app.Type);cat4=categories(app.Horizon);cat5=categories(app.SiNo);
colu={'char' 'logical' 'char' {cat{:}} 'char' {cat2{:}} 'char' {cat3{:}} {cat4{:}} {cat5{:}} 'char' 'char' 'char' 'char' 'logical'};
app.UITable.ColumnFormat=colu;
app.SaveAsButton.Visible="off";
app.SaveButton.Visible="off";
app.Edit_Button.Visible='off';
...
..
colu={'char' 'logical'.. ===> i set "logical" the second column of table
then i go in app designer and i change value of "On" (pics 1.png), i save it
and i check it using import(file)
and i see similar to this (see 2.png)
i see true and false.... (but having set the field as logical they should all be 0/1)

 채택된 답변

Adam Danz
Adam Danz 2023년 7월 19일
편집: Adam Danz 2023년 7월 19일

0 개 추천

2.png indicates that the data is a 82x15 string where some values in col 2 are in the form "true"/"false" whereas other values in col 2 are in the form "0". How are you reading in this data? You can convert this mix of strings to a logical vector using one of the options below.
Option 1: string comparison
str = ["false","1","true","0"];
bool = ismember(lower(str),["true","1"])
bool = 1×4 logical array
0 1 1 0
However, if any unexpected values such as "2" appear in the string, this will convert them to false. To validate the conversion, this line will throw an error if there are any unexpected strings.
assert(all(ismember(lower(str),["true","false","1","0"])),"String values must represent boolean values.")
Option 2: Class conversion
str = ["false","1","true","0"];
bool = arrayfun(@(s)logical(str2num(s)),str)
bool = 1×4 logical array
0 1 1 0
However, if any unexpected values such as "2" or "F" appear in the string, this may either throw an error or silently return a logical value. To validate the conversion, use the same assert validation in option 1.
Option 3: Specify varopts when reading the data
If these data are read into MATLAB, you could use T = readtable(filename,opts) and set opts using setvaropts. In setvaropts you can specify,
opts = setvaropts(opts,'mybool',...
"TrueSymbols",["true","1"],...
"FalseSymbols",["false","0"]);
This is demonstrated well in this answer by @Jeremy Hughes.

댓글 수: 3

shamal
shamal 2023년 7월 19일
이동: Voss 2023년 7월 19일
hi,thank for answer
You write: "How are you reading in this data? "
Simple..see pics 3-4
in the starting situation they are all "1" ..therefore the values ​​are correct The problems come when I click on the box
I click on the box to select or deselect it.. then it's the code that does the update
i use this function to update the data you enter in the table.. but I've seen that it doesn't always update them
function UITableCellSelection(app, event)
%indices = event.Indices;
app.MyTable=app.UITable.Data; %MESSO PER VIA DI UN BUG DI MATLAB CHE NON AGGIORNA LA TABELLA!
disp(app.MyTable(:,2))
[r,~]=size(app.MyTable); %%MI AGGIORNA IL NUM STRATEGIE
app.CurrentNumberStrategy=double(r);
app.TotalstrategiesloadedTextArea.Value=string(r);
app.SaveAsButton.Visible="off";
app.SaveButton.Visible="off";
end
Thanks for the explanation. This is because the logical values are converted to strings:
string(true)
ans = "true"
string(false)
ans = "false"
Instead of storing the data in a string array, is there a reason you could not use a table in which case the column that stores these values can be logical?
shamal
shamal 2023년 7월 19일
i want to use a table because i am displaying data in table format in app designer
I can however convert the data before it is saved to app.MyTable=app.UITable.Data;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2023년 7월 19일

댓글:

2023년 7월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by