How to create an an array of unknown size?
조회 수: 2 (최근 30일)
이전 댓글 표시
Say, I have an array A of size 100 consisting of 0's and 1's. I need to create a smaller array consisting only of the 1's. At start, I don't know the number of 1's in the original array. Basically, I want to create the subset-array element-by-element as I loop over the elements of the original array and checking for 1's.Any help appreciated. Thanks, Preetam
댓글 수: 1
per isakson
2015년 8월 16일
"create the subset-array element-by-element as I loop over the elements "   is that a requirement or a hint?
답변 (2개)
Star Strider
2015년 8월 15일
I’m not quite sure what you want.
Here are two possibilities:
Array = randi([0 1], 1, 100);
OnesArray = Array(Array==1) % Ones Array
ElemArray = find(Array); % Indices Of Ones In ‘Array’
댓글 수: 0
참고 항목
카테고리
Help Center 및 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!