フィルターのクリア

How to store different # of values, obtained in iterations, in Matrix / array ?

1 回表示 (過去 30 日間)
Matt Learner
Matt Learner 2012 年 7 月 28 日
If I have some matrix/ array say A(x,y) where 'x' is iteration # (lets consider here 2 iterations) and 'y' is # of values in that iteration. Now during 1st iteration if I obtain 5 values, I store it in A (1,:) i.e. for example,
A(1,1) = 2, A(1,2) = 9, A(1,3) = 1, A(1,4) = 4 A(1,5) = 8.
then in second iteration if I know that I will obtain only 2 values and I want it to be stored in A(2,:) i.e.,
A(2,1) = 5; A(2,2) = 7.
How to store only 2 values? Because Matlab automatically takes A(2,3) , A(2,4) and A(2,5) as zeros.
I don't want the matlab to automatically allocate space for zeros. I mean I want to get only the space as A(1,:) = 5 values and A(2,:) as 2 values and I don't want zeros stored or the space to store it.
I hope some one can understand my question correctly and if you did Could you please let me know How can I do that?
  2 件のコメント
Matt Learner
Matt Learner 2012 年 7 月 29 日
I tried to format my question, I hope it helps

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

回答 (1 件)

Ryan
Ryan 2012 年 7 月 29 日
編集済み: Ryan 2012 年 7 月 29 日
I think I deciphered your question enough to give you an answer: use cell notation.
A{n}
All rows/columns of a matrice are required to be the same length, hence why it's padding your shorter rows with 0's, but cell notation lets you store different size vectors, matrices and strings in an array.
  2 件のコメント
Matt Learner
Matt Learner 2012 年 7 月 29 日
編集済み: Matt Learner 2012 年 7 月 29 日
Thanks for your help. I am still not clear,
So could you please provide an example for a 2 dimension matrix with different size vectors ( may be u can show the code using the example I provided above)?
Oleg Komarov
Oleg Komarov 2012 年 7 月 29 日
Basically, you cannot have a matrix with varying row or column dimension.
What you can do is store the rows into the so called cell array. Each cell will have one double row vector (row) with its own dimensional properties.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by