need to skip iterations in a for loop

2 次查看(过去 30 天)
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.

采纳的回答

Chunru
Chunru 2022-4-25
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by