MATLAB: Create a matrix with a for loop

matrix

Hey there!
I am attempting to create a matrix which has n, s, k, and i as columns. However, I keep getting this error no matter how I try to make the matrix:
Subscript indices must either be real positive integers or logicals.
Is there a way around this problem considering that I need to make a list that comprises of numbers that aren't positive integers?
for i = -3:.5:2
k = 10^i;
n = (100 / k);
s = sqrt((-.5^2 .* ((100 / k)-(.5.*(100 / k)))./(100-(100 / k)))./((((100 / k)-(.5.*(100 / k)))./(100-(100 / k)))-1));
if (0<s) && (s<=1)
s = s;
elseif s > 1 || (isnan(s)==1)
s = 1;
elseif isreal(s) == 1
s = 0;
else
s = 0;
end
RTIlogk{i} = [i k n s];
end

Best Answer

Yes. Create a vector from your original ā€˜iā€™, then refer to it by subscript.
This works:
iv = -3:.5:2;
for i = 1:numel(iv)
k = 10^iv(i);
n = (100 / k);
s = sqrt((-.5^2 .* ((100 / k)-(.5.*(100 / k)))./(100-(100 / k)))./((((100 / k)-(.5.*(100 / k)))./(100-(100 / k)))-1));
if (0<s) && (s<=1)
s = s;
elseif s > 1 || (isnan(s)==1)
s = 1;
elseif isreal(s) == 1
s = 0;
else
s = 0;
end
RTIlogk{i} = [i k n s];
end