Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Kunal Roy
Kunal Roy el 17 de Sept. de 2016
Comentada: mizuki el 18 de Sept. de 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 comentario
mizuki
mizuki el 18 de Sept. de 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))

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by