Multiple element storing in a row

16 Ansichten (letzte 30 Tage)
Ozge Moral
Ozge Moral am 8 Nov. 2015
Bearbeitet: Ozge Moral am 8 Nov. 2015
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.

Akzeptierte Antwort

Stephen23
Stephen23 am 8 Nov. 2015
Bearbeitet: Stephen23 am 8 Nov. 2015
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 Kommentar
Ozge Moral
Ozge Moral am 8 Nov. 2015
Bearbeitet: Ozge Moral am 8 Nov. 2015
I applied to my question, it works. Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by