how to rearrange the code in simple way
1 次查看(过去 30 天)
显示 更早的评论
input1=q(1,1:419); output1(1:419)=0;
input2=q(2,1:419); output2(1:419)=0;
input3=q(3,1:419); output3(3:419)=0;
input4=q(4,1:419); output4(4:419)=0;
input5=q(5,1:419); output5(5:419)=0;
input6=q(6,1:419); output6(6:419)=0;
input7=q(7,1:419); output7(7:419)=1;
input8=q(8,1:419); output8(8:419)=1;
input9=q(9,1:419); output9(9:419)=1;
input10=q(10,1:419); output10(10:419)=1;
input = [input1 input2 input3 input4 input5 input6 input7 input8 input9 input10]; output = [output1 output2 output3 output4 output5 output6 output7 output8 output9 output10];
would its possible to write in the looping statement in easy manner sir
0 个评论
采纳的回答
Jan
2013-7-18
An important programming method is to avoid the inclusion of indices in the names of the variables. While it is rather tedious to access "output1, output2, ..." in is much easier to use an index as index(!):
output(1), output(2), ...
Btw, Do you mean "output2(1:419)" or should the zeros of output2 start at the 2nd element? Such typos frequently happen, when huge blocks of code with almost repeated names are written. So this is much easier:
output = rand(10, 1000);
for k = 1:10
output(k, k:419) = 0;
end
0 个评论
更多回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!