boundaries.m

%源程序
function B=boundaries(BW,conn,dir) 
%BOUNDARIES Trace object boundaries. 
%B=BOUNDARIES(BW) traces the exterior boundaries of objects in the binary 
%image BW.B is a p_by_1 cell array,where p is the number of objects in the 
%image.Each cell contains a Q_by_2 matrix,each row of which contains the 
%row and column coordinates of a boundary pixel.Q is the number of boundary 
%pixels for the corresponding object.Object boundaries are traced in the 
%clockwise direction. 
% 
%B=BOUNDARIES(BW,CONN) specifies the connectivity to use when tracing  
%boundaries.CONN may be either 8 or 4.The default value for CONN is 8. 
% 
%B=BOUNDARIES(BW,CONN,DIR) specifies the direction used for tracing  
%boundaries.DIR should be either 'cw'(trace boundaries clockwise) or  
%'ccw'(trace boundaries counterclockwise).If DIR is omitted BOUNDARIES 
%traces in the clockwise direction. 
if nargin<3   %nargin定义在用户自定义函数体内,nargin返回 
              %用来调用函数的变量的个数。 
    dir='cw'; 
end 
if nargin<2 
    conn=8; 
end 
L=bwlabel(BW,conn); %返回值是矩阵L,大小同BW,包含了BW中的连通部分的标记 
%The number of objects is the maximum value of L.Initialize the cell 
%array(元包数组)B so that each cell initially contains a 0_by_2 matrix. 
numObjects=max(L(:));%寻找L中所作标记中的最大值,这个最大值实际上就对应着L中 
% 包含的最多的连通部分的数目。 
if numObjects>0 
    B={zeros(0,2)};%元包数组中仅包含一个元素。 
    B=repmat(B,numObjects,1);%将B进行numObjects*1个复制构成新的B。 
else 
    B={}; 
end 
%Pad label matrix with zeros.This lets us write the boundary_following loop 
%without worrying about going off the edge of the image. 
Lp=padarray(L,[1 1],0,'both'); 
%Compute the linear indexing offsets to take us from a pixel to its 
%neighbors. 
M=size(Lp,1);%SIZE(X,1) returns the number of rows.  

if conn==8 
    %Order is N NE E SE S SW W NW. 
    offsets=[-1,M-1,M,M+1,1,-M+1,-M,-M-1]; 
else 
    %Order is N E S W. 
    offsets=[-1,M,1,-M]; 
end 
%next_search_direction_lut is a lookup table.Given the direction from pixel 
%k to pixel k+1,what is the direction to start with when examining the 
%neighborhood of pixel k+1? 
if conn==8 
    next_search_direction_lut=[8 8 2 2 4 4 6 6]; 
else 
    next_search_direction_lut=[4 1 2 3]; 
end 
%next_direction_lut is a lookup table.Given that we just looked at neighbor 
%in a given direction,which neighbor do we look at next? 
if conn==8 
  next_direction_lut=[2 3 4 5 6 7 8 1]; 
else 
  next_direction_lut=[2 3 4 1]; 
end 
%Values used for marking the starting and boundary pixels. 
START=-1; 
BOUNDARY=-2; 
%Initialize scratch space in which to record the boundary pixels as well as 
%follow the boundary. 
scratch=zeros(100,1); 
%Find candidate starting locations for boundaries. 
[rr,cc]=find((Lp(2:end-1,:)>0)&(Lp(1:end-2,:)==0)); 
rr=rr+1; 
for k=1:length(rr) 
    r=rr(k); 
    c=cc(k); 
    if (Lp(r,c)>0)&(Lp(r-1,c)==0)&isempty(B{Lp(r,c)}) 
        %We've found the start of the next boundary.Compute its linear 
        %offset,record which boundary it is,mark it,and initialize the 
        %counter for the number of boundary pixels. 
        idx=(c-1)*size(Lp,1)+r; 
        which=Lp(idx); 
        scratch(1)=idx; 
        Lp(idx)=START; 
        numpixels=1; 
        currentpixel=idx; 
        initial_departure_direction=[]; 
        done=0; 
        next_search_direction=2; 
        while ~done 
            %Find the next boundary pixel. 
            direction=next_search_direction; 
            found_next_pixel=0; 
            for k=1:length(offsets) 
                neighbor=currentpixel+offsets(direction); 
                if Lp(neighbor)~=0 
                    %Found the next boundary pixel. 
                    if (Lp(currentpixel)==START)&... 
                        isempty(initial_departure_direction) 
                    %We are making the initial departure from the starting 
                    %pixel. 
                    initial_departure_direction=direction; 
                    elseif (Lp(currentpixel)==START)&... 
                            (initial_departure_direction==direction) 
                       % We are about to retrace our path. 
                       %That means we're done. 
                       done=1; 
                       found_next_pixel=1; 
                       break; 
                    end 
                    %Take the next step along the boundary. 
                    next_search_direction=... 
                        next_search_direction_lut(direction); 
                    found_next_pixel=1; 
                    numpixels=numpixels+1; 
                    if numpixels>size(scratch,1) 
                        %Double the scratch space. 
                        scratch(2*size(scratch,1))=0; 
                    end 
                    scratch(numpixels)=neighbor; 
                    if Lp(neighbor)~=START 
                       Lp(neighbor)=BOUNDARY; 
                    end 
                    currentpixel=neighbor; 
                    break; 
                end 
                direction=next_direction_lut(direction); 
            end 
            if ~found_next_pixel 
                %If there is no next neighbor,the object must just have a 
                %single pixel. 
                numpixels=2; 
                scratch(2)=scratch(1); 
                done=1; 
            end 
        end 
        %Convert linear indices to row_column coordinates and save in the 
        %output cell array. 
        [row,col]=ind2sub(size(Lp),scratch(1:numpixels)); 
        B{which}=[row-1,col-1]; 
    end 
end 
if strcmp(dir,'ccw') 
    for k=1:length(B) 
        B{k}=B{k}(end:-1:1,:); 
    end 
end

model Unnamed11 ThermalSystems.HeatExchangers.FinAndTube.MoistAirLiquid.CrossFlowHX crossFlowHX( liquidType=sim.liquidType1, gasType=sim.gasType1, redeclare model TubeSideHeatTransferModel = ThermalSystems.HeatExchangers.FinAndTube.TransportPhenomena.TubeSideHeatTransfer.GnielinskiDittusBoelter, redeclare model FinSideHeatTransferModel = ThermalSystems.HeatExchangers.FinAndTube.TransportPhenomena.FinSideHeatTransfer.Haaf) annotation (Placement(transformation(extent={{-14,-2},{14,26}}))); inner ThermalSystems.SystemInformationManager sim(redeclare TSMedia.GasTypes.TSMedia_MoistAir gasType1, redeclare TSMedia.LiquidTypes.TSMedia_Water liquidType1) annotation (Placement(transformation(extent={{80,78},{100,98}}))); ThermalSystems.LiquidComponents.JunctionElements.VolumeJunction junction( TInitial=298.15) annotation (Placement(transformation( extent={{-4,-4},{4,4}}, rotation=90, origin={-50,0}))); ThermalSystems.HeatExchangers.FinAndTube.MoistAirLiquid.CrossFlowHX crossFlowHX1( liquidType=sim.liquidType1, gasType=sim.gasType1, redeclare model TubeSideHeatTransferModel = ThermalSystems.HeatExchangers.FinAndTube.TransportPhenomena.TubeSideHeatTransfer.GnielinskiDittusBoelter, redeclare model FinSideHeatTransferModel = ThermalSystems.HeatExchangers.FinAndTube.TransportPhenomena.FinSideHeatTransfer.Haaf) annotation (Placement(transformation(extent={{-14,-66},{14,-38}}))); ThermalSystems.LiquidComponents.Boundaries.Boundary boundary(boundaryType="p") annotation (Placement(transformation(extent={{28,-62},{36,-42}}))); ThermalSystems.LiquidComponents.Boundaries.Boundary boundary1(boundaryType="p") annotation (Placement(transformation(extent={{32,0},{40,20}}))); ThermalSystems.LiquidComponents.Boundaries.Boundary boundary2( liquidType=sim.liquidType1, boundaryType="m_flow", m_flowFixed=-2000, V_flowFixed=-2) annotation (Placement(transformation(extent={{-82,-10},{-74,10}}))); ThermalSystems.GasComponents.Boundaries.Boundary boundary3(boundaryType="V_flow", V_flowFixed=-3.6) annotation (Placement(transformation(extent={{56,28},{64,48}}))); ThermalSystems.GasComponents.Boundaries.Boundary boundary4(boundaryType="V_flow", V_flowFixed=-3.6) annotation (Placement(transformation(extent={{64,8},{72,28}}))); ThermalSystems.GasComponents.Boundaries.Boundary boundary5(boundaryType="p") annotation (Placement(transformation(extent={{32,-28},{40,-8}}))); ThermalSystems.GasComponents.Boundaries.Boundary boundary6(boundaryType="p") annotation (Placement(transformation(extent={{34,-88},{42,-68}}))); equation connect(junction.portC, crossFlowHX.portA_liq) annotation (Line( points={{-50,4},{-50,12},{-14,12}}, color={0,170,238}, thickness=0.5)); connect(junction.portB, crossFlowHX1.portA_liq) annotation (Line( points={{-50,-4},{-50,-52},{-14,-52}}, color={0,170,238}, thickness=0.5)); connect(crossFlowHX1.portB_liq, boundary.port) annotation (Line( points={{14,-52},{32,-52}}, color={0,170,238}, thickness=0.5)); connect(boundary1.port, crossFlowHX.portB_liq) annotation (Line( points={{36,10},{36,12},{14,12}}, color={0,170,238}, thickness=0.5)); connect(boundary2.port, junction.portA) annotation (Line( points={{-78,0},{-66,0},{-66,2.22045e-16},{-54,2.22045e-16}}, color={0,170,238}, thickness=0.5)); connect(boundary4.port, crossFlowHX1.portA_gas) annotation (Line( points={{68,18},{76,18},{76,-32},{0,-32},{0,-38}}, color={255,153,0}, thickness=0.5)); connect(boundary3.port, crossFlowHX.portA_gas) annotation (Line( points={{60,38},{0,38},{0,26}}, color={255,153,0}, thickness=0.5)); connect(crossFlowHX.portB_gas, boundary5.port) annotation (Line( points={{0,-2},{0,-18},{36,-18}}, color={255,153,0}, thickness=0.5)); connect(crossFlowHX1.portB_gas, boundary6.port) annotation (Line( points={{0,-66},{0,-78},{38,-78}}, color={255,153,0}, thickness=0.5)); annotation (uses( ThermalSystems(version="1.10.0"), TSMedia(version="1.10.0"), Modelica(version="4.0.0"))); end Unnamed11; 在dymola中运行这段代码后报错Translation of Unnamed11: The problem is structurally singular. It has 1722 scalar unknowns and 1722 scalar equations. The Real part has 1722 unknowns and 1722 equations. The Integer part has 0 unknowns and 0 equations. The Boolean part has 0 unknowns and 0 equations. The String part has 0 unknowns and 0 equations. Attempting to further localize singularity. The model Unnamed11 is structurally singular. The model includes the following hints: A liquid mass flow rate cannot be uniquely calculated. The reason could be that - a hydraulic capacitor object (ThermalSystems.LiquidComponents.HydraulicCapacitor) or - a liquid boundary type "p" is missing, to define the pressure inside a liquid circuit, or - a connector of a liquid component is not connected. The problem is structurally singular for the element type Real. Translation aborted. WARNINGS have been issued. ERRORS have been issued. 请问是什么问题,该如何解决
最新发布
08-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值