trying to generate a sweep sine wave that increases its frequency till an upper limit and then starts decreasing its frequency to the lower limit
I think that in your simulation, you only calculate the instantaneous frequency, but then fail to compute the phase for the sin() function correctly.

This is how you could correct this issue:

% parameters of linear up/down-sweep
freq1 = 20;
freq2 = 200;
fs = 44100;

% length of a sweep in one direction
endTime = 0.1;

% number of samples of a sweep in one sweep direction
N = endTime * fs;

% instantaneous frequency at each point in time ...
% ... first increasing for N points, then decreasing for N points
inst_f = [linspace(freq1, freq2, N) linspace(freq2, freq1, N)];

% since (in continuous time) instantaneous frequency is derivative of
% phase, we have to compute the "integral" to get the phase for sin().
phi = 2 * pi * cumsum(inst_f) / fs;
sweep = sin(phi);

% plotting
t = linspace(0, endTime * 2, length(s));
plot(t, sweep);

% wavwrite(sweep, fs, 32, '~/sweep_delete.wav');