updating gui script 2016 hobject
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi, About 3-4 years back, I wrote a complex script that generated a gui and allowed users to select individual data points and delete them (and restore them) as necessary for quality control of a data set. I haven't written anything with a gui since but now running the script on 2016 version is causing it to fail. I understand that it's to do with the new graphics system but I'm not sure how to correct the issue - can anyone help?
for j=1:9999
[x1,y1,button]=ginput(1);
if ctdT
clickedAx = gca;
if j ==1
sh = hObject(1,1:3);
hObjectCopy = hObject(1,4:6);
end
clickedAx= sh==clickedAx;
hObject = hObjectCopy(clickedAx);
udata = get(hObject,'UserData');
X=get(hObject,'XData');
Y=get(hObject,'YData');
XScale=diff(get(gca,'XLim'));
YScale=diff(get(gca,'YLim'));
end
if button==1
r=sqrt(((X-x1)./XScale).^2+((Y-y1)./YScale).^2);
[~,i(j,1)]=min(r);
x(j,1)=X(i(j));
y(j,1)=Y(i(j));
hold on;
if ctdT
scatter(x(j,1),y(j,1),50,'m', 'filled','tag',[hObject,'spikepoints']) % this line
udata = [udata;x,y,i];
udata = unique(udata,'rows');
set(hObject,'UserData',udata)
else
scatter(x(j,1),y(j,1),50,'m', 'filled','tag','spikepoints')
end
end
later on, I have this code to plot the deleted data so it's easy to see where the data have been removed from.
sp = findobj(gcf,'tag',[hObject(i),'spikepoints']);
if ~isempty(sp)
X = get(sp,'xdata'); if iscell(X); X = cell2mat(X);end
Y = get(sp,'ydata');if iscell(Y); Y = cell2mat(Y);end
scatter(sh(i),X,Y,10,'k+','tag','ghosts')
delete(sp)
end
so I want to be able to refer back to each datapoint.
The error I get is:
Error using matlab.graphics.chart.primitive.Line/horzcat
Conversion to matlab.graphics.chart.primitive.Line from char is not possible.
Error in P_1498_able>removeSpikesSubplot (line 2516)
sp = findobj(gcf,'tag',[hObject(i),'spikepoints']);
I've read through the release notes and used the file exchange 'fixer', but I'm none the wiser. Can anyone point me in the right direction so I can update this script?
댓글 수: 0
답변 (2개)
Jan
2017년 2월 15일
I cannot run your code, but perhaos this helps:
% scatter(x(j,1),y(j,1),50,'m', 'filled','tag',[hObject,'spikepoints']);
tag = sprintf('%.16gspikepoints', double(hObject));
scatter(x(j,1),y(j,1),50,'m', 'filled','tag', tag);
But it is not clear to me, why the tag, which is a string, should contain the handle of GUI object. This seems to be buggy in older Matlab versions also.
댓글 수: 0
Guillaume
2017년 2월 15일
It's puzzling how your code worked. Even before the graphics change, the Tag property required a char array and as far as a recalled a line handle was never a char array, so you couldn't concatenate it with one.
If your scatter Tag does require a way to identify the line handle it is associated with, you could create it with
'Tag', sprintf('%u_spikepoints', typecast(double(hObject), 'uint64'))
%basically convert the line handle to double which is guaranteed to be unique
%then convert this double value to a unique string (here by just printing the bit values as 64-bit integer)
Or better, when you create the line, give it a unique tag, and create your scatter tag with
'Tag', [hObject.Tag, 'spikepoint']
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!