MATLAB: How can i vectorize this for loop

control systemMATLAB

close all
clear all
clc
tic;
i=1;
for k=1:0.5:10;
for a=1:0.5:5;
numpl(i,:) =k;
denpl(i,:) =[1 a 0];
i=i+1;
end
end
w=[.1,.5,.8,1,2,8,15,50,100];
P=freqcp(numpl,denpl,w);
toc

Best Answer

You could do:
n1 = numel(1:0.5:10);
n2 = numel(1:0.5:5);
numpl2 = repelem(1:0.5:10,n2)';
denpl2 = repmat([ones(n2,1),(1:0.5:5)',zeros(n2,1)],n1,1);
ps: you can edit your code with the button '{} Code' when you write a question, in order to make it easier to read.