필터 지우기
필터 지우기

How can I create an dynamically increasing array to store positions?

조회 수: 1 (최근 30일)
Kunal Roy
Kunal Roy 2016년 9월 17일
댓글: mizuki 2016년 9월 18일
load iris.dat
for i:size(iris,2)-1
if (iris(:,i)==iris(1,1)
%store the row number in a dynamically increasing array (could be a cell array, or any %other matlab structure
%Please explain in simple terms. I am new to matlab
  댓글 수: 1
mizuki
mizuki 2016년 9월 18일
Do you want to find elements in iris(:,1) (the first column) that are same as iris(1,1)? If so, the following code can:
load iris.dat
j = 1;
for i=1:size(iris,1)-1
if ( iris(i,1)==iris(1,1) )
idx(j) = i; % store the row# which has the same element with iris(1,1)
j = j+1;
end
end
I do not recommend you to make a code which includes the variable that increases the size of the variable dynamically because it takes much more time than creating a variable in one time like:
find(iris(:,1) == iris(1,1))

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by