Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Kunal Roy
Kunal Roy am 17 Sep. 2016
Kommentiert: mizuki am 18 Sep. 2016
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 Kommentar
mizuki
mizuki am 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))

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by