I really thanks in advance any help. I am trying to use the below command to find any variable from the A member of the B, but encountering with the error. Welcome any suggestion.
[~,JINDX] = cellfun(@(x)(ismember(B,x)),A,'Uni',false);
Error using cell/ismember (line 34)
Input A of class cell and input B of class char must be cell arrays of strings, unless one is a string.
Error in @(x)(ismember(B,x))
34 error(message('MATLAB:ISMEMBER:InputClass',class(a),class(b)));

1 件のコメント

Stephen23
Stephen23 2020 年 2 月 18 日
編集済み: Stephen23 2020 年 2 月 18 日
It is not clear what you expect. Cell array A contains Rx1 character arrays,e.g.:
>> A{1}
ans =
6
9
0
0
8
0
5
while cell array B contains scalar numerics (which would be much better store in once numeric array):
>> B{1}
ans = 6900805
Do you expect that Rx1 character vector to be equivalent to that numeric scalar? For example:
>> Anum = str2double(cellfun(@(v)v(:).',A,'uni',0));
>> Bnum = [B{:}];
>> idx = ismember(Bnum,Anum)
idx =
1 0 0 0 0 0 0 0 0 0

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

 採用された回答

KSSV
KSSV 2020 年 2 月 18 日

0 投票

load("example.mat") ;
N = length(A) ;
A1 =zeros(N,1) ;
for i = 1:N
A1(i) = str2num(A{i}') ;
end
B1 = cell2mat(B)' ;
[c,ia] = ismemebr(A1,B1) ;

6 件のコメント

Stephen23
Stephen23 2020 年 2 月 18 日
@KSSV: you already know that str2double is preferred over str2num, and that it does not require a loop.
KSSV
KSSV 2020 年 2 月 18 日
Ohh..yes...
Farshid Daryabor
Farshid Daryabor 2020 年 2 月 18 日
Yes, replaced str2num to str2double. Thanks again
Farshid Daryabor
Farshid Daryabor 2020 年 2 月 18 日
Dear KSSV,
the problem is when I want to use ia as index to find the corresponding variable,
>> C = D(ia);
Subscript indices must either be real positive integers or logicals.
KSSV
KSSV 2020 年 2 月 18 日
Show us the whole code...in the give answer
A1(c)
works fine.
Farshid Daryabor
Farshid Daryabor 2020 年 2 月 18 日
great, it's work to me also. Thanks

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by