非常感谢,将你的找边界代码稍作修改。
终于实现了读数据,找边界并进行圆拟合的功能
% Fit a circle from a text data
%
[filename, pathname] = uigetfile('*.txt','Open Data');
filepath = strcat(pathname,filename);
if length(filepath) == 0
return;
end
Data = textread(filepath,'','delimiter',';','emptyvalue',NaN); %需根据具体情况修改
pcolor(Data), axis equal,axis tight, shading interp;
colorbar; hold on;
% find the boundary and fit to a circle
BoundIdx = []; BoundIdy = [];
for k1=1:size(Data,1)
NaNIdx=find(isnan(Data(k1,:)));
JumpSize=diff(NaNIdx);
BI=find(JumpSize>=2);
BINum = length(BI);
if ~(isempty(BI))
BoundIdx = [BoundIdx NaNIdx(BI(1)) NaNIdx(BI(BINum)+1)];
BoundIdy = [BoundIdy k1 k1];
end
end
[xc,yc,R,a] = circfit(BoundIdx,BoundIdy);
t = linspace(0,pi*2,100);
z = xc+yc*i+R*exp(i*t);
plot(BoundIdx,BoundIdy,'kx');
plot(z); hold off; |