Multiple element storing in a row
조회 수: 9 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Particle Swarm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!