is there any simple code for this to solve larger matrices?

13 ビュー (過去 30 日間)
Aimen Mujahid
Aimen Mujahid 2017 年 3 月 14 日
編集済み: Jan 2017 年 3 月 14 日
function b =check(Q)
Qmd2(1,1)=Q(1);
Qmd2(2,1)=Q(2);
Qmd2(3,1)=Q(3);
Qmd2(1,2)=Q(4);
Qmd2(2,2)=Q(5);
Qmd2(3,2)=Q(6);
disp(Qmd2);
c=[1 2;1 3;1 4];
b=c.*Qmd2;
disp(b);
  2 件のコメント
Stephen23
Stephen23 2017 年 3 月 14 日
編集済み: Stephen23 2017 年 3 月 14 日
Jan
Jan 2017 年 3 月 14 日
@Aimen: Please explain what you want to achieve. How will c look like if the input has 8 elements?

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

回答 (1 件)

Jan
Jan 2017 年 3 月 14 日
編集済み: Jan 2017 年 3 月 14 日
A bold guess - I'm not sure what you exactly want:
function b = check(Q)
Q = Q(:);
n = numel(Q);
b = [Q(1:n / 2), Q(1+n/2:n) .* (2:1+n/2).'];
This works for inputs with an even size of elements only.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by