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

1 ビュー (過去 30 日間)
Asad Abbas 2017 年 5 月 17 日

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 件のコメント表示非表示 4 件の古いコメント
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 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, :)]

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

### Community Treasure Hunt

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

Start Hunting!

Translated by