フィルターのクリア

How to separate a vector into sub-vectors?

5 ビュー (過去 30 日間)
Taner Cokyasar
Taner Cokyasar 2016 年 7 月 6 日
コメント済み: Taner Cokyasar 2016 年 7 月 7 日
Assume, I have the following vector Zs (9x1):
0
0
1
0
1
0
0
1
0
I want to create sub-vectors such that each of them will include three numbers in the Zs, consecutively.
For example,
Zs1 = [0; 0; 1]
Zs2 = [0; 1; 0]
Zs3 = [0; 1; 0]
Thanks,
  6 件のコメント
Taner Cokyasar
Taner Cokyasar 2016 年 7 月 6 日
編集済み: Taner Cokyasar 2016 年 7 月 6 日
Assume, m = 3
k = 1:m; %k is a row vector and every Zs is a column vector.
k*Zs(1) = scalar
k*Zs(2) = scalar2
k*Zs(3) = scalar3
If scalar>scalar2, do something... Otherwise, don't do anything.
If scalar>scalar3, do something... Otherwise, don't do anything.
If scalar2>scalar3, do something... Otherwise, don't do anything.
This is basically, what I am trying to do. "do something" means to create a constraint to be used in intlinprog. Intlinprog uses A, Aeq, b, beq... matrices to solve the problem. I will need to compare "scalar" values and either put a number into "matrix b" (which is a required matrix for intlinprog) or not.
I am planning to calculate "scalar" values first. Then, maybe I can create a for loop to compare them. According to the result of whichever scalar is SMALLER, its corresponding f value ( f values are in the data) will be subtracted from the LARGER scalar's f value.
Stephen23
Stephen23 2016 年 7 月 7 日
@Taner Cokyasar: Don't create lots of variables like that! You will only make your code much slower, more complicated, and buggy. Oh, it it will also be much harder to debug! Read thsi carefully to know why:
The best solution: Keep your data in one variable, and learn to use indices effectively.

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

採用された回答

James Tursa
James Tursa 2016 年 7 月 6 日
編集済み: James Tursa 2016 年 7 月 7 日
Don't do that. Use cell arrays or some other method instead. E.g., see this link:
EDIT 7/6/2016:
OK, based on what you have recently posted, try this:
k = your row vector
Zs = your large column vector
n = numel(k);
scalars = k * reshape(Zs,n,[]);
The elements of scalars will be the values you want.
  1 件のコメント
Taner Cokyasar
Taner Cokyasar 2016 年 7 月 7 日
Thank you so much, James!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by