| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1296 人关注过本帖
标题:Function '.*' is not defined for values of class 'cell'.
只看楼主 加入收藏
xiaojikuaipao62
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-5-27
收藏
 问题点数:0 回复次数:0 
Function '.*' is not defined for values of class 'cell'.
function [MBR,MBF]=MCRGSA()
%第一步:常用变量声明,以及种群初始化
M=7;
N=50;
Pm=0.009;
K=5;
t0=5;
alpha=0.9;
beta=1;
Source=1;
End={8,6};
Num={3,2};

ROUTES=[1 2 5 8;1 4 7 8;1 3 7 8;1 2 5 6;1 4 5 6];
Cost= [0 14 13 12 -1 -1 -1;14 0 -1 -1 18 -1 -1;13 -1 0 9 -1 -1 17;12 -1 9 0 15 -1 8;-1 18 -1 15 0 16 -1;-1 -1 -1 -1 16 0 -1;-1 -1 17 8 -1 -1 15];     
Num_end=length(End);%组播目的节点个数
farm=zeros(N,Num_end);%种群
for i=1:Num_end
    farm(:,i)=unidrnd(Num(i),50,1);%随机生成初始种群
end
m=1;
t=t0;
MBR=zeros(M,Num_end);
MBF=zeros(M,1);
while m<=M%设置停止条件
   
    %第二步:按照变异概率调节参数进行变异以及退火选择
    P=Num./sum(Num);
    P=Pm.*P;
    for i=1:N%对每一个个体都执行
        Code=farm(i,:);%临时取出
        k=1;
        while k<=K%每一个温度下改变K次
            for j=1:Num_end
                if rand<P(j)
                    Bit=randperm(Num(j));
                    pos=find(Bit~=Code(j));
                    Code(j)=Bit(pos(1));
                end
            end
            fit1=ShiYinZhi(ROUTES,Cost,farm(i,:));%计算适应值
            fit2=ShiYinZhi(ROUTES,Cost,Code);
            if fit2<fit1
                farm(i,:)=Code;
            elseif rand<exp((fit1-fit2)/(fit1*t));
                farm(i,:)=Code;
            else
                Code=farm(i,:);
            end
            k=k+1;
        end
    end
   
    %第三步:交叉算法
    Farm=zeros(size(farm));
    for i=1:2:(N-1);
        a=farm(i,:);
        b=farm(i+1,:);
        pos=unidrnd(Num_end-1);
        A=[a(1,1:pos),b(1,(pos+1):end)];
        B=[b(1,1:pos),a(1,(pos+1):end)];
        Farm(i,:)=A;
        Farm(i+1,:)=B;
    end
    FARM=[farm;Farm];
   
    %第四步:选择复制操作
    fitness=zeros(1,2*N);
    for i=1:(2*N)
        fitness(i)=ShiYinZhi(ROUTES,Cost,FARM(i,:));
    end
    maxfitness=max(fitness);
    minfitness=min(fitness);
    pos=find(fitness==maxfitness);
    MBR(m,:)=FARM(pos(1),:);
    MBF(m)=minfitness;
    for i=1:(2*N)
        fitness(i)=((maxfitness-fitness(i))/(maxfitness-minfitness+0.00005))^beta;
    end
    fitness=fitness./(sum(fitness)+0.000000005);
    FITNESS=zeros(size(fitness));
    Sgn=FITNESS;
    for i=1:(2*N)
        FITNESS(i)=sum(fitness(1:i));
    end
    while sum(Sgn)<N
        Pos=find(FITNESS>=rand);
        if length(Pos)>0
          Sgn(Pos(1))=1;
        end
    end
    POS=find(Sgn==1);
    for i=1:N
        farm(i,:)=FARM(POS(i),:);
    end
    farm(unidrnd(N),:)=MBR(m,:);
   
    %更新参数
    m=m+1
    t=t*alpha;
end
plot(MBF)
title('遗传模拟退火算法收敛图')
xlabel('进化代数')
ylabel('费用')
%译码计算适应值的函数
%ROUTES--------备选路径集
%Cost----------费用邻接矩阵
%Code----------组播树的编码
%fit-----------组播树的总代价作为适应值
function fit=ShiYinZhi(ROUTES,Cost,Code)
CC=zeros(size(Cost));
for i=1:length(Code)
    R=ROUTES{i}{Code(i)};
    J=length(R)-1;
    for j=1:J
        a=R(j);
        b=R(j+1);
        CC(a,b)=Cost(a,b);
    end
end
fit=sum(sum(CC));
??? Error using ==> .*
Function '.*' is not defined for values of class 'cell'.

Error in ==> C:\MATLAB6p5\toolbox\stats\unidrnd.m
On line 26  ==> r = ceil(n.*rand(rows,columns));

Error in ==> C:\MATLAB6p5\work\MCRGSA.m
On line 19  ==>     farm(:,i)=unidrnd(Num(i),50,1);%随机生成初始种群

请高手帮忙看看怎么回事,小女子不胜感激!正在做毕业设计!先谢谢各位了!
搜索更多相关主题的帖子: cell Function values defined Num 
2008-05-27 09:02
快速回复:Function '.*' is not defined for values of class 'cell'.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036070 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved