未定义的功能' lt'类型为' cell'的输入参数.在使用细胞 [英] Undefined function 'lt' for input arguments of type 'cell'. in using cell

查看:165
本文介绍了未定义的功能' lt'类型为' cell'的输入参数.在使用细胞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的老师要求我们在MATLAB中编写用于Huffmam编码的程序,但是遇到了一个问题:

My teacher asked us to write a program for Huffmam Coding in MATLAB, but I met a problem:

类型为'cell'的输入参数的未定义函数'lt'.

Undefined function 'lt' for input arguments of type 'cell'.

work5455中的错误(第49行)

Error in work5455 (line 49)

这是哪一行:

if(cell{k+1}(1)<cell{k}(1)&&cell{k}(2)==-1)

由于没有'lt',我该如何解决? 我的老师太忙了,无法回复我的电子邮件..... 这是代码(未完成),非常感谢!

Since there is no 'lt',how can I solve it? My teacher is just too busy to answer my e-mail..... Here`s the code(not finished),thank you very much!

fprintf('Reading data...')
data=imread('C:\Users\dell\Desktop\2.png');
data=rgb2gray(data);
data=uint8(data);
fprintf('Done!\n')

if~isa(data,'uint8'),
    error('input argument must be a uint8 vector')
end
f=repmat(0,1,256);
len=length(data);
for j=0:255
    for i=1:len
        if data(i)==j;
            f(j)=f(j)+1;
        end
    end
end

f=double(f./len);

simbols=find(f~=0);
f=f(simbols);
[f,sortindex]=sort(f)
simbols=simbols(sortindex)

len=length(simbols);
codeword=cell(1,len);
huffnode=cell(1,2*len);
for i=1:len
    cell{i}={f(i),-1,-1,-1};
end
for i=len+1:2*len-1
    cell{i}={-1,-1,-1,-1};
end

m=len
%for i=1:len
for j=1:len+i-1
    m=m-1;
    for k=1:m
        if(cell{k+1}(1)<cell{k}(1)&&cell{k}(2)==-1)
            cell{2*len}=cell{k+1};
            cell{k+1}=cell{k};
            cell{k}=cell{2*len};
        end
    end
end

推荐答案

像元{k + 1}(1)的输出是一个1x1像元.由于无法将单元格与其他单元格进行比较,因此必须使用cell2mat进行数据类型转换,以获取数字本身.使用

The Output of cell{k+1}(1) is a 1x1 cell. Since you cannot compare cells to other cells, you have to make a datatype conversion using cell2mat to get the number itself before. Using

if(cell2mat(cell{k+1}(1))<cell2mat(cell{k}(1))&&cell2mat(cell{k}(2))==-1)

应该解决您的问题.
由于单元格是matlab中的内置函数,因此我强烈建议重命名您的变量.如@AndrasDeak在评论中所述,否则稍后可能会出现问题.通常,永远不要使用内置的函数名作为变量名或函数名.请注意,ij代表matlab中的虚数单位,因此也不应该用作迭代变量.

should solve your Problem.
Since cell is a built-in function in matlab I would highly recommend renaming your variable. As @AndrasDeak stated in the comments you might get Problems later on otherwise. In General, you should never use built-in function-names as your variable- or function-names. Please note that i and j represent the imaginary unit in matlab and thus should not be used as Iteration variables either.

这篇关于未定义的功能&amp;#39; lt&amp;#39;类型为&amp;#39; cell&amp;#39;的输入参数.在使用细胞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆