MATLAB Answers

0

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

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
2017 年 5 月 17 日
Asad - the error is coming from
allcomb(num2cell(a,2),num2cell(b,2)
What is the intent behind the above line of code? Are you trying to create a cell array allcomb and then convert it to a matrix? Note that a has three rows whereas b has two. How do you expect to combine them? What final result are you trying to obtain?
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 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.

サインイン to comment.

タグ

1 件の回答

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 件のコメント

サインイン to comment.



Translated by