need to skip iterations in a for loop

2 views (last 30 days)
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.

Accepted Answer

Chunru
Chunru on 25 Apr 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

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!