From: Bill on
How do you concatenate all of the values generated by the following for loop to make a vector?

for i=1:3
a=exp(i)
end
From: Oleg Komarov on
"Bill " <user12345678(a)hotmail.com> wrote in message <i11g9e$dvu$1(a)fred.mathworks.com>...
> How do you concatenate all of the values generated by the following for loop to make a vector?
>
> for i=1:3
> a=exp(i)
> end

Do not concatenate inside a loop if you know the final dimension in advance. Preallocate the output and assign it:

a = zeros(1,3);
for ii=1:3
a(ii) = exp(ii)
end

Also, don't use "i" (imaginary unit) because it is already in the standard matlab "library".

Oleg
From: James Tursa on
"Bill " <user12345678(a)hotmail.com> wrote in message <i11g9e$dvu$1(a)fred.mathworks.com>...
> How do you concatenate all of the values generated by the following for loop to make a vector?
>
> for i=1:3
> a=exp(i)
> end

a = exp(1:3)

James Tursa