Try this:
T=3; for i=1:T A(i,:)=circshift([ones(1,T) zeros(1,T^2-T)],T*(i-1)); end
Try this:
T=3; for i=1:T A(i,:)=circshift([ones(1,T) zeros(1,T^2-T)],T*(i-1)); end
That is exactly what blkdiag is for:
>> V = [1,1,1]; >> blkdiag(V,V,V) ans = 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1
This is much simpler and much more efficient than trying to write your own code using loops. Remember that MATLAB is a high-level language, so loops are often not the best solution.
@Stefano Di Vito: using the method that Sean de Wolski showed. It uses a comma-separated list to provide as many input arguments as you want:
https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html
https://www.mathworks.com/matlabcentral/answers/320713-how-to-operate-on-comma-separated-lists
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!