Clear Filters
Clear Filters

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

1 view (last 30 days)
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 Comment
mizuki
mizuki on 18 Sep 2016
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))

Sign in to comment.

Answers (0)

Categories

Find more on Data Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!