adding ones at the end of an array
이전 댓글 표시
can you help me to add ones at the end of 2*3 matrix to change it to 5*3 matrix. i want not zeros .
답변 (1개)
KALYAN ACHARJYA
2019년 3월 1일
편집: KALYAN ACHARJYA
2019년 3월 1일
k=randi(3,3)
k =
3 3 2
3 3 1
3 2 3
>> k=[k;ones(2,3)]
k =
3 3 2
3 3 1
3 2 3
1 1 1
1 1 1
>>
댓글 수: 2
Guillaume
2019년 3월 1일
I'd recommend
k = [k; ones(2, size(k, 2))];
to make it work for k of any size. In general, never hardcode the size of matrices if you get ask matlab for it.
KALYAN ACHARJYA
2019년 3월 1일
@Guillaume Thanks
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!