根据两个向量的笛卡尔积构造Matlab矩阵

时间:2020-07-27 12:32:48

标签: arrays matlab matrix

考虑两个Matlab向量@RequestMapping("api/v1") //get token for staff (AD user) HttpBasic auth @PostMapping("auth/get/stafftoken") public ResponseEntity<?> getToken() { // some code... HttpHeaders tokenHeaders = new HttpHeaders(); tokenHeaders.setBearerAuth(tokenAuthenticationService.getToken()); return new ResponseEntity<>(tokenHeaders, HttpStatus.OK); } //get JWT if code from sms == code in my CRM-system (for client) not auth - permitAll @PostMapping("send/clienttoken") public @ResponseStatus ResponseEntity<?> sendVerifyCode(@RequestParam("verifycode") String verifycode) { // some code... HttpHeaders tokenHeaders = new HttpHeaders(); tokenHeaders.setBearerAuth(tokenAuthenticationService.getToken()); return new ResponseEntity<>(tokenHeaders, HttpStatus.OK); } @RequestMapping("api/v2") @GetMapping("get/contract/{number:[0-9]{6}") public Contract getContract(@PathVariable String number) { return contractsService.getContract(number); } A=[1 2 3 4 5];

我希望您建议编写大小为B=[6 7 8 9 10]的Matlab矩阵C,其中每一行都有:

  • 作为第一个元素32x5A(1)
  • 作为第二个元素B(1)A(2)
  • 作为第三个元素B(2)A(3)
  • 作为第四元素B(3)A(4)
  • 作为第五个元素B(4)A(5)

B(5)不应包含相等的行。 C来自32,其中2^55A的长度。

B

我可以手动记下 C=[1 2 3 4 5; %all elements from A (1 row) 6 2 3 4 5; %one element from B (5 rows) 1 7 3 4 5; 1 2 8 4 5; 1 2 3 9 5; 1 2 3 4 10; 6 7 3 4 5; %two elements from B (10 rows) ... ; 6 7 8 4 5; %three elements from B (10 rows) ... ; 6 7 8 9 5; %four elements from B (5 rows)] ... ; 6 7 8 9 10; %all elements from B (1 row)] ,但我想知道是否有更快的构建方法。

1 个答案:

答案 0 :(得分:1)

类似的方法作为我对your previous question的回答:

A = [1 2 3 4 5];
B = [6 7 8 9 10];
N = numel(A);
t = dec2bin(0:2^N-1)-'0';
[~, ind_sort] = sortrows([sum(t,2) -t]);
t = t(ind_sort, :);
AB = [A B];
ind_AB = t*N + (1:N); % or bsxfun(@plus, t*N, 1:N) in old Matlab versions
result = AB(ind_AB);
相关问题