How do I create a 1x21 matrix where the inputs are all the different values of d

2 ビュー (過去 30 日間)
Romina
Romina 2019 年 9 月 14 日
コメント済み: the cyclist 2019 年 9 月 14 日
B=[1 2 3 4 5 6 7; 9 11 13 15 17 19 21];
for i=1:7
for j=1:7
if i>j
P=B(:,i);
Q=B(:,j);
Norm=zeros(1,nchoosek(7,2));
d=norm(P-Q)
k=1:nchoosek(7,2);
Norm(:,k)=d
end
end
end

採用された回答

the cyclist
the cyclist 2019 年 9 月 14 日
Does this code do what you had intended? (There was some guesswork on my part.)
B=[1 2 3 4 5 6 7; 9 11 13 15 17 19 21];
Norm=zeros(1,nchoosek(7,2));
k = 0;
for i=1:7
for j=1:7
if i>j
k = k+1;
Norm(k) = norm(B(:,i)-B(:,j));
end
end
end
  2 件のコメント
Romina
Romina 2019 年 9 月 14 日
Yes! Thank you very very much!!!
the cyclist
the cyclist 2019 年 9 月 14 日
Great. I suggest you carefully compare my code with yours, to understand the things that I did differently.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by