how to index in a more efficient way?
how to index in a more efficient way?
I have written a matlab code that works okay but I want to write it in a more efficient way (I don't want to repeat my self an I want to make it dry).
at first I create a matrix of ones (28*8) and then I want to change some of its elements to minus ones.
here is the code:
a=ones(28,8);
for i=1:7
j=1;
a(i,j)=-1;
end
for i=8:13
j=2;
a(i,j)=-1;
end
for i=14:18
j=3;
a(i,j)=-1;
end
for i=19:22
j=4;
a(i,j)=-1;
end
for i=23:25
j=5;
a(i,j)=-1;
end
for i=26:27
j=6;
a(i,j)=-1;
end
for i=28:28
j=7;
a(i,j)=-1;
end
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.