Weird UITextArea behaviour working with Strings
이전 댓글 표시
Hello, I am reading data from a piece of equipment and dumping it into a UITextarea (orange text)
When I read out the contents of the text area and its class, I get this:

The line pointed to by the arrow isn't relevant. I am after the following numbers to plot (1st 2 columns), i.e. 0 - 836, 1-772 etc
But my plotting routine failed. I think its because the actual data is the 4th entry in the cell array and is just one big string.
Strangely, when I just click in the UITextArea and check the data again, its fine and my plot routing works. It seems the action of clicking has split the long string into individual entries now.

This is my plot routine:
ST=app.MessagesTextArea.Value;
ST=string(ST);
[sy,sx]=size(ST);
data=[];
for i=1:sy
S=ST(i);
TF = contains(S,"focus"); %Ignore the actual calling command
if S=="" || TF==1
continue
end
Sline=split(S)';
n=numel(Sline);
if n>3
S1=Sline(1,1);
S2=Sline(1,2);
data(i,1)=str2double(S1);
data(i,2)=str2double(S2);
end
end
%remove any rows with zeros
data = data(any(data,2),:);
% if data(1,2)==0
% data(1,:)=[];
% end
ax=app.UIAxes3;
cla(ax,'reset');
plot(ax, data(:,1),data(:,2),'.-','Color',cl); grid(ax,"on");
What can i do the avoid having the manually click in the UITextArea to "break my data up" so I can plot it.
(Im not sure if this is relevant, but this is how I get the data initially into the textArea using TCP connection)
data = read(tcpclientObj,nb,"string"); %tcpclientObj this has already been setup
str = formattedDisplayText(data);
ReportMessage(app,str); % this is my own function do display str in the UITextArea
function ReportMessage(app,msg)
currString=get(app.MessagesTextArea,'Value');
%currString=[{char(msg)};currString]; %add to top of message box
currString=[currString; {char(msg)}]; %add to bottom of message box
app.MessagesTextArea.Value=currString;
drawnow;
scroll(app.MessagesTextArea,'bottom');
end
Thanks
Jason
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!