Undefined function 'eq' for input arguments of type 'cell error

112 ビュー (過去 30 日間)
sermet
sermet 2014 年 5 月 13 日
コメント済み: Walter Roberson 2016 年 6 月 10 日
txt1=[{'a'},{'b'},{'c'}];
txt1=txt1(:);
data=[{'a'},{'b'}];
data=data(:);
[row,col] = find(txt1==data)
%it gives
Undefined function 'eq' for input arguments of type 'cell'. error.

採用された回答

per isakson
per isakson 2014 年 5 月 13 日
編集済み: per isakson 2014 年 5 月 13 日
Replace
txt1==data
by
ismember( txt1, data )
and see documentation of ismember

その他の回答 (2 件)

David Sanchez
David Sanchez 2014 年 5 月 13 日
You can also do:
txt1=[{'a'},{'b'},{'c'}];
txt1=txt1(:);
data=[{'a'},{'b'}];
data=data(:);
idx = getnameidx(txt1,data)
idx =
1 2

iris jogin
iris jogin 2016 年 6 月 10 日
編集済み: Walter Roberson 2016 年 6 月 10 日
[mdata,mtext,mraw]=xlsread('o.xlsx');
L=length(mraw);
[D,T,R]=xlsread('Ori.xlsx');
l=length(R);
for i=1:339
A(i)=mraw(i);
end
for j=1: 63314
B(j)=R(j);
end
for i=1:339
for j=1: 63314
if B(j)==A(i)
xlswrite('gotermofO.xlsx',B(j),'A1');
end
end
end
Undefined function 'eq' for input arguments of type 'cell error
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 6 月 10 日
if isequal(B(j), A(i))
This makes no assumptions about the data types: it should work whether the cells are strings or numbers.
Caution: length() is the largest dimension, not the first dimension. Your mraw is generally going to be a 2D array, not a vector.
For efficiency you could be using
A = mraw(1:339);
B = R(1:53314);
Are you sure that you only want a single cell output into the spreadsheet ? Your code overwrites cell A1 each time it finds a match.
Your matching code could be much more efficient if your cells are all numeric or are all strings: in that case you could use ismember(B, A) to do the matching "in bulk"

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by