Borrar filtros
Borrar filtros

need to skip iterations in a for loop

3 visualizaciones (últimos 30 días)
John Hendricks
John Hendricks el 25 de Abr. de 2022
Comentada: John Hendricks el 25 de Abr. de 2022
I'm trying to set values in a row of a large 2D matrix to 1, but i need to skip every two entries, so have my last row look something like 1001001001 instead of my current L(bottomrow,:)=1. I was thinking about using a for loop but i'm not so sure how to set that up, I tried
L=zeros(1024,1024);
for n=(2:1022:3)
L(1024,n)=1
end
using n from 2 to 1022 because i'm using dummy arrays for my code.

Respuesta aceptada

Chunru
Chunru el 25 de Abr. de 2022
L=zeros(1024,1024);
% for n=(2:1022:3)
% L(1024,n)=1
% end
% Set the last row (first end), column 2 to last column with a step 3 to be
% 1 (you can adjust this for your need)
L(end, 2:3:end) = 1;
L(end, :)
ans = 1×1024
0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0
  1 comentario
John Hendricks
John Hendricks el 25 de Abr. de 2022
Thanks for helping a matlab newbie such as myself :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by