フィルターのクリア

What is the best way to create a vector with a special sequence of subvectors

1 回表示 (過去 30 日間)
reza hajargasht
reza hajargasht 2020 年 2 月 24 日
コメント済み: darova 2020 年 2 月 24 日
I have say 100 vectors of equal size (v1 to v100) and I want to create a vector V of the following structure: V=[v1-v2 ;...; v1-v100; v2-v3; ... , v2-v100; .... .... .... ; v98-v99 ; v98-v100; v99-v100]. What is the best way to create V?
  2 件のコメント
Stephen23
Stephen23 2020 年 2 月 24 日
編集済み: Stephen23 2020 年 2 月 24 日
"What is the best way to create V?"
The Best Way: Simply by store your data in one matrix, then your task requires some basic array manipulation.
The Worst Way: Using numbered variables is a sign that you are doing something wrong. Accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug:
darova
darova 2020 年 2 月 24 日
Only one idea i have: using for loop. What do you think about it?

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

採用された回答

Stephen23
Stephen23 2020 年 2 月 24 日
編集済み: Stephen23 2020 年 2 月 24 日
Store the vectors in one matrix, then you just need to use nchoosek to generate the required indices:
>> M = randi(9,5,3) % each row = one vector
M =
5 6 9
9 2 5
4 5 1
4 8 2
9 6 6
>> X = nchoosek(1:size(M,1),2);
>> Z = M(X(:,1),:) - M(X(:,2),:)
Z =
-4 4 4
1 1 8
1 -2 7
-4 0 3
5 -3 4
5 -6 3
0 -4 -1
0 -3 -1
-5 -1 -5
-5 2 -4

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by