Function 'subsindex' is not defined for values of class 'cell'.

1 回表示 (過去 30 日間)
Asad Abbas
Asad Abbas 2017 年 5 月 17 日
回答済み: Guillaume 2017 年 5 月 17 日
Please guide me.
a = [1,0,1;1,1,0;1,1,1];
b = [0,1;1,0];
allcomb = [];
When I run this below command
cell2mat(allcomb(num2cell(a,2),num2cell(b,2)))
I have error "Function 'subsindex' is not defined for values of class 'cell'."
  5 件のコメント
Geoff Hayes
Geoff Hayes 2017 年 5 月 17 日
Asad - how do you expect to get the answer (that you have posted) given a and b? it looks like b is the repeated (column-wise) three times, but what happens with a? You probably should describe the steps or rules that you expect to be followed.
Asad Abbas
Asad Abbas 2017 年 5 月 17 日
編集済み: Asad Abbas 2017 年 5 月 17 日
I am trying to combine matrix. I did it with "repmat" but its only feasible where both matrix dimensions are different as I have given example here. But If dimensions are same then it dont give me unique combinations such as.
a= [1, 0; 0, 1]
b= [1, 0; 0, 1]
It gives me final combinations by using "repmat" (Not unique combinations)
ans=
1 0 1 0
0 1 0 1
1 0 1 0
0 1 0 1
But I want solution (all unique):
ans =
1 0 1 0
0 1 1 0
1 0 0 1
0 1 0 1
All combinations are unique.

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

採用された回答

Guillaume
Guillaume 2017 年 5 月 17 日
One possible way of generating your desired output:
a = [1,0,1;1,1,0;1,1,1];
b = [0,1;1,0];
[rowa, rowb] = ndgrid(1:size(a, 1), 1:size(b, 1));
allcomb = [a(rowa, :), b(rowb, :)]

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by