# how to make a function (named pcc ) that solves the cartesian product of 2 strings A(with n elements) and B(with m elements)?

조회 수: 8(최근 30일)
Cosmin Grab 2018년 3월 27일
답변: Roger Stafford 2018년 4월 3일
intputs n, m, A, B output pcc

댓글을 달려면 로그인하십시오.

### 답변(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표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

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.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Direct Search in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by