MATLAB: Generating array of data using for-end looping

generating data

I want to generate an array of number using for-end, i know that I can generate logarithmic series using logspace, but in this case, i can't use that
so I run this code:
function y=generate
for i=1:20
j(i)=10^((i-1)/2);
for l=1:5;
y(l)=j(i)+l/5*j(i)*sqrt(10);
end
end
result1=[y'];
my expectation is that I can generate logarithmic series of 100 number from 10^0 to 10^9.5, but instead getting 100 numbers, I run it and only get these:
ans =
1.0e+010 *
0.5162 0.7162 0.9162 1.1162 1.3162
then what should I do to get the 100 numbers, I need the '20' on 'i=1:20' in other function, that's why i can't use logspace because logspace can't be use inside looping command (for-end). Please I need your advice and I am just a beginner.
I appreciate your help

Best Answer

result1=zeros(1,100);p=1; %create a vector to save the values and the index
for i=1:20
j(i)=10^((i-1)/2);
for l=1:5;
y(l)=j(i)+l/5*j(i)*sqrt(10);
result1(p)=y(l); p=p+1; %save current value and increment index
end
end
result1; %your vector with the values
I didn't check if the values are correct, just plot(result1) and it does look like something logarithmic
Edit: You can't use the logspace function but maybe you can steal the logspace code ;)
d1=0;d2=9.5;n=100;
result1 = (10).^ [d1+(0:n-2)*(d2-d1)/(floor(n)-1), d2];
Related Question