how to make a function (named pcc ) that solves the cartesian product of 2 strings A(with n elements) and B(with m elements)?
3 次查看(过去 30 天)
显示 更早的评论
intputs n, m, A, B output pcc
0 个评论
回答(2 个)
David Goodmanson
2018-4-3
编辑:David Goodmanson
2018-4-3
Hi Cosmin,
If by 'strings' you mean vectors of characters then there are questions about how to accomplish multiplication. If you mean vectors of numbers, then in this context the Cartesian product is the same as the outer product, multiplication of a column vector by a row vector:
a = [1 2 3].'
b = [4 5 6 7]
a*b
ans =
4 5 6 7
8 10 12 14
12 15 18 21
0 个评论
Roger Stafford
2018-4-3
Assume A and B are row strings.
C = [reshape(repmat(A,length(B),1),[],1),repmat(B(:),length(A),1)];
The two-element rows of C will contain all possible pairs of elements of A and B.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Report Generator 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!