Effacer les filtres
Effacer les filtres

how to rearrange the code in simple way

2 vues (au cours des 30 derniers jours)
ajith
ajith le 18 Juil 2013
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

Réponse acceptée

Jan
Jan le 18 Juil 2013
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

Plus de réponses (2)

Andrei Bobrov
Andrei Bobrov le 18 Juil 2013
ii = reshape(q(1:10,1:419)',[],1)'; % your 'input'

Iain
Iain le 18 Juil 2013
Modifié(e) : Iain le 18 Juil 2013
input = reshape(q(1:10,1:419)',1,[]);
output = zeros(10,419);

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by