フィルターのクリア

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 Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by