updating gui script 2016 hobject

2 次查看(过去 30 天)
Rachel
Rachel 2017-2-15
回答: Guillaume 2017-2-15
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?

回答(2 个)

Jan
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.

Guillaume
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']

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by