Spliting a n-by-3 Array into several different arrays.

2 ビュー (過去 30 日間)
Scott Salazar
Scott Salazar 2018 年 9 月 6 日
コメント済み: Stephen23 2018 年 9 月 7 日
So, I have the following array:
v =
[1 2 3;
-1 2 -3;
0 0 0;
1 -2 3;
1 2 3;
1 2 3;
0 0 0;
0 0 0;
1 1 1]
I would like to split it into several arrays that I can call upon later as follows:
v_1 = [1 2 3; -1 2 -3],
v_2 = [1 -2 3; 1 2 3; 1 2 3],
v_3 = [1 1 1];
How would I go about doing this. I would like to use the zeros as an indication of where to create another variable with the array indicated.
Thank you.
  5 件のコメント
dpb
dpb 2018 年 9 月 7 日
I know you asked that, but do NOT go down that perilous pathway..."There be dragons!"
Stephen23
Stephen23 2018 年 9 月 7 日
"...but I would again like to call them each from a vector. Thoughts?"
Do NOT do that. Magically accessing variable names is one way the beginners force themselves into writing slow, complex, buggy code. Here is why:

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

採用された回答

dpb
dpb 2018 年 9 月 6 日
v is not a vector but an array.
Star's code works on a vector; would be painful to extend to an array I think, as is. BUT, you can create a vector to use to find the split locations by his technique and then select the array instead of vector.
Define the auxiliary vector as
aux=all(v==0,2);

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by