Multiple element storing in a row

9 ビュー (過去 30 日間)
Ozge Moral
Ozge Moral 2015 年 11 月 8 日
編集済み: Ozge Moral 2015 年 11 月 8 日
I have a problem about storing multiple elements in a row of an array. I have long code, but i can post short portion of it. There is a ant cell array ( it can be a multidimensional array). After some conditions, this ant{} values will change, but there is some condition multiple element will store in a row.
n=20;
for i=1:n
ant(i,:,t)= {i};
ph(i,:,t)=1;
del_ph(i,:,t)=0;
end
ant =
[ 1]
[ 2]
[ 3]
[ 4]
[ 5]
[ 6]
[ 7]
[ 8]
[ 9]
[10]
[11]
[12]
[13]
[14]
[15]
[16]
[17]
[18]
[19]
[20]
After calculations and some conditions, [8],[9] and [10] will move in [9], and store in this row. I did correctly move other ant{} but not reach the multiple element storing. My expected result is In this below, or like this.
ant =
[ 0]
[ 1]
[ 2]
[ 3]
[ 4]
[ 5]
[ 6]
[ 7]
[ 8] [ 9] [ 10]
[11]
[12]
[13]
[14]
[15]
[16]
[17]
[18]
[19]
[20]
[ 0]
I tried to write a code but i think i'm bad at using arrays, so i'm stuck. Can you give me any idea? If this question isn't clear, i can post whole code and i can try explain exactly. Sorry, if i repeat same question.

採用された回答

Stephen23
Stephen23 2015 年 11 月 8 日
編集済み: Stephen23 2015 年 11 月 8 日
Try concatenating those values into one numeric vector:
>> ant = num2cell(1:10)' % fake data
ant =
[ 1]
[ 2]
[ 3]
[ 4]
[ 5]
[ 6]
[ 7]
[ 8]
[ 9]
[10]
>> ant{3} = [ant{3:5}]; % concatenate those values
>> ant(4:5) = [] % delete unwanted cells
ant =
[ 1]
[ 2]
[1x3 double]
[ 6]
[ 7]
[ 8]
[ 9]
[ 10]
>> ant{3}
ans =
3 4 5
  1 件のコメント
Ozge Moral
Ozge Moral 2015 年 11 月 8 日
編集済み: Ozge Moral 2015 年 11 月 8 日
I applied to my question, it works. Thank you!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by