필터 지우기
필터 지우기

how to rearrange the code in simple way

조회 수: 2 (최근 30일)
ajith
ajith 2013년 7월 18일
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

채택된 답변

Jan
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

추가 답변 (2개)

Andrei Bobrov
Andrei Bobrov 2013년 7월 18일
ii = reshape(q(1:10,1:419)',[],1)'; % your 'input'

Iain
Iain 2013년 7월 18일
편집: Iain 2013년 7월 18일
input = reshape(q(1:10,1:419)',1,[]);
output = zeros(10,419);

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by