声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 7815|回复: 9

[编程技巧] Function definitions are not permitted at the prompt or in scripts 出错求助

[复制链接]
发表于 2008-4-8 15:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
Error: Function definitions are not permitted at the prompt or in scripts.
这是什么错误?
我的function是function [BW,Datay1,Datay2,Datax]=image2data(filename,BWLevel,GridLevelx,GridLevely,DataYstart,DataYstep,DataXstep)

[ 本帖最后由 eight 于 2008-4-8 16:53 编辑 ]
回复
分享到:

使用道具 举报

发表于 2008-4-8 16:00 | 显示全部楼层

回复 楼主 的帖子

函数定义格式错误!
也许是你没有那么多输出结果吧。
发表于 2008-4-8 16:12 | 显示全部楼层
从你写的函数形式看,好像没有什么错误,应该是程序内部,有关输出函数的地方有些问题
 楼主| 发表于 2008-4-8 16:20 | 显示全部楼层
我把整个程序贴出来吧

function [BW,Datay1,Datay2,Datax]=image2data(filename,BWLevel,GridLevelx,GridLevely,DataYstart,DataYstep,DataXstep)
filedata=imread(filename);
BW = im2bw(filedata,BWLevel);
imshow(BW);
filesize=size(BW);
Lx=filesize(2);%%%%%%%%%%%x
Ly=filesize(1);%%%%%%%%%%%%%%%%%y
%%%%%%%%%%%%%%%%%%%%找到XY坐标轴
Lxstart=0;%%%%%%%%%%%y开始的地方
Ldeltax=0;
Ldelta=0;
Ldeltai=1;
for Li=1:Lx
    temp=0;
    for Lj=1:Ly
        if BW(Lj,Li)==0
            temp=temp+1;
        end
    end
    if temp>Ly*GridLevely %%%%%%%%%%%%%%%表明是网格
        BW(1:Ly,Li)=1;%%%%%%%%%%%%grid off
        Ldelta(Ldeltai)=Li;
        Ldeltai=Ldeltai+1;
        %if Lxstart==0
        %    Lxstart=Li;
        %end
    end
end
Lxstart=1;
Lxstop=1;
for Li=1:temp
    if (BW(Lystep(Li),Ldelta(Lxstart)+1:Ldelta(Lxstart)+7)<4)%六个中有三个黑,则认为是标轴
        BW(Lystep(Li),Ldelta(Lxstart)+1:Ldelta(Lxstart)+7)=ones(1,7);
        if sum((BW(Lystep(Li),:)))>(1-GridLevelx)*Lx
        tfalse=0;
        ti=1;
        while(tfalse==0)
            if(BW(Lystep(Li),Ldelta(Lxstart)+7+ti)==0)
                BW(Lystep(Li),Ldelta(Lxstart)+7+ti)=1;
            else
                tfalse=1;
            end
            ti=ti+1;
        end
        end
    end
end
Lxstop=floor(mean(Ldelta(Lxstop:Ldeltai-1)));

Ldeltax=Ldelta(2)-Ldelta(1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%去 网格
%%%%%%%%%%%%%%%%%去Y轴

filesize=size(BW);
Lx=filesize(2);%%%%%%%%%%%x
Ly=filesize(1);%%%%%%%%%%%%%%%%%y
imshow(BW);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Lynumber=0;
temp=0;
for Li=1:Lx
    if Li==361
        Li=361;
    end
    Datax(Li)=Li;
    number=find(BW(1:Ly,Li)==0);
    numbersize=size(number);
    Lynumber(Li)=numbersize(1);
    if numbersize(1)>0%%%%%%%%%%%%%%有数据
        if numbersize(1)<2%%%%%%%%%%%%%%%刚好有两个点
            if numbersize(1)==1
                Datay1(Li)=number(1);
               % Datay2(Li)=number(2);
               %else
               %%Datay1(Li)=number(1);
               %Datay2(Li)=0;
            end
        elseif numbersize(1)>1%%%%%%%%%%%%%%有很多点,就空
            
            temp1=0;
            %temp(1)=number(1);
            temp=number(1);
            Datay1(Li)=0;
%            Datay2(Li)=0;
            for LLi=2:numbersize(1)
                if (number(LLi)-number(LLi-1))<3   %%%%%%%%%表示这两个点很近,认为是一个点
                    temp(LLi-temp1)=number(LLi);
                else%%%%%%%%%%%%%%%%%%有离开的点
                    %%%%%%%%%%%%%%%%%%%取前两个点进行复制
            %        if Datay1(Li)==0&Datay2(Li)==0
            %            Datay1(Li)=floor(mean(temp));
            %        elseif Datay1(Li)>0&Datay2(Li)==0
           %             Datay2(Li)=floor(mean(temp));
           %         end
                    %%%%%%%%%%%%%%%%%%%%%%%%%%%
                    temp=number(LLi);
                    temp1=LLi-1;
                    

                end
            end
            %%%%%%%%%%%%%%%%%55无离开的点,
            if temp1==0
                Datay1(Li)=floor(mean(temp));
           %     Datay2(Li)=0;
            end
           % if Datay2(Li)==0&temp1>0
           %     Datay2(Li)=floor(mean(temp));
           % end
            
        end
    else  %%%%%%%%%%%%无数据
            Datay1(Li)=0;
            Datay2(Li)=0;
    end
if Datay1(Li)==0&Li>1
    Datay1(Li)=Datay1(Li-1);
end
%if Datay2(Li)==0&Li>1
%    Datay2(Li)=Datay2(Li-1);
%end
number;
Datay1(Li);
%Datay2(Li);
%figure(3);
%plot(Datay1);
end



%%%%将前面由于判断坐标去掉的点加上
temp=min(find(Datay1>0));
if temp>1
    Datay1(1:temp-1)=ones(1,temp-1)*Datay1(temp);
end
发表于 2008-4-8 16:53 | 显示全部楼层
发帖前搜索了吗?看版规了吗?你的帖子标题不符合规定。如果你把能看的置顶帖都看了,你就不会犯这些错误,你的问题也就能找到答案了

[ 本帖最后由 eight 于 2008-4-8 16:54 编辑 ]
发表于 2008-4-8 17:06 | 显示全部楼层

回复 4楼 的帖子

%             Datay2(Li)=floor(mean(temp));

你这把Datay2输出给屏蔽掉了,少了输出个数!
发表于 2008-4-8 17:15 | 显示全部楼层
发表于 2008-4-8 17:26 | 显示全部楼层
function [BW,Datay1,Datay2,Datax]=image2data(filename,BWLevel,GridLevelx,GridLevely,DataYstart,DataYstep,DataXstep)

不在同一行?
发表于 2008-4-8 18:10 | 显示全部楼层
原帖由 donkeyxu 于 2008-4-8 17:26 发表
function =image2data(filename,BWLevel,GridLevelx,GridLevely,DataYstart,DataYstep,DataXstep)

不在同一行?
函数不能写在命令窗口
发表于 2008-4-9 17:44 | 显示全部楼层

回复 9楼 的帖子

晕倒!这个有点隐蔽。
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-23 13:25 , Processed in 0.057556 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表