Generate signals with a particular variance and SNR
It depends on what you mean by SNR. It's a common joke in the DSP community to spell it out as "something to noise ratio", referring to the fact that there is no unique definition of SNR, so the term by itself means nothing.

Define it yourself and use it appropriately.

What's common is to define it as ${\rm SNR} = \frac{P_{\rm s}}{P_{\rm n}}$ where $P_{\rm s}$ is the power (variance) of the signal samples ($x_n$ in your notation) and $P_{\rm n}$ is the power (variance) of the noise samples.

Hence:

P_s = 1;   % target signal power
SNR = 15;  % target SNR in dB
P_n = P_s / 10^(SNR/10); % calculated noise power

s = randn(1,N)*sqrt(P_s);
v = randn(1,N)*sqrt(P_n);
y = a*s + v;


You don't need the for loop there by the way. You can use the awgn function, it should do something very similar. Again, there is no clear need for it though.

Note that this definition of the SNR is independent of a. Depending on your application this may be desirable or undesirable. In the latter case, you can include it in your SNR definition. Feel free to do so. Just define everything very clearly.

*edit: In response to your question: the SNR is really a ratio of signal power to noise power. So to change the SNR, you can change both. If you want the SNR to be 10 dB higher, you can decrease the noise variance by 10 or alternatively increase the signal variance by 10.

If you want to change the SNR while keeping the noise variance fixed (say, 1), you're welcome to do so. Almost the same approach:

P_n = 1;   % target noise power
SNR = 15;  % target SNR in dB
P_s = P_n / 10^(-SNR/10); % calculated signal power

s = randn(1,N)*sqrt(P_s);
v = randn(1,N)*sqrt(P_n);
y = a*s + v;


This also means looking at the noise variance itself doesn't tell you about the SNR conditions. If you assume it's 1 this can mean a low SNR (if the signal power is, say, below 1) or a high SNR (if it is much higher than 1).