Borrar filtros
Borrar filtros

Save output of a for loop in a vector

2 visualizaciones (últimos 30 días)
basma awad
basma awad el 31 de Ag. de 2021
Editada: Stephen23 el 31 de Ag. de 2021
Hello,
Am doing a for loop cheecking if the i ellement of a vector is equal to the nth element
target = zeros(1,150)';
for i = 4:numel(str)
target= isequal(str(i), str(i-3))
end
how to i save the output of target in one vector ? now it only gives me logic values 0 or 1 and for each i value. I wich to save the output in a row vector
Thank u

Respuestas (1)

Stephen23
Stephen23 el 31 de Ag. de 2021
Editada: Stephen23 el 31 de Ag. de 2021
str = 'hello world. eat lots of bananas.';
target = zeros(150,1);
for k = 4:numel(str)
target(k) = isequal(str(k), str(k-3));
end
Checking:
disp(target)
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Categorías

Más información sobre GPU Computing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by