Create a vector that only the first element and the last element is 0
8 次查看(过去 30 天)
显示 更早的评论
B=zeros(mx,1);
for z=1:mx
if B(z,1) == B(1,1)
B(z,1) = 0;
elseif B(z,1) == B(mx,1)
B(z,1) = 0;
else
B(z,1) = 1;
end
end
I want to create a vector B that only (1,1) and (mx,1) equal to 0 but from (2 to mx,1) equal to 1. But my code still only show a zero matrix. How can I fix that?
0 个评论
回答(1 个)
KSSV
2017-1-25
编辑:KSSV
2017-1-25
N = 10 ; % length of the vector
iwant = ones(N,1) ;
iwant(1) = 0 ;
iwant(N) = 0 ;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!