Q:

How do you assign random variables to elements in an array of a user specified size?

enter image description hereif i have a vector (n,1), where 'n' is a user specified number.
how can i assign a variable to each element of the vector randomly or at least uniquely in a 'for' or 'while'loop using MATLAB.
My aim is to give a symbolic answer to each of the variables in a system of linear equations which i have  used the 'MATLAB rref()' function to convert the equations into a solvable form.
I know i have to do this in symbolic form.
E.g n=10 variable vector (10,1), requires 10 unique variables which are selected by the computer.
This question is also open to best alternatives!
Thanks 

A:

First Method:
The easiest way is to use the command sym itself.
n = 7;
A = sym('A',[1 n])

A =

[ A1, A2, A3, A4, A5, A6, A7]

This lets you to perform symbolic operations on the symbols:
>> A(1)+A(2)-A(5)

ans =

A1 + A2 - A5

there are other ways to generate unique variables though.

Second Method:
Just use the genvarname function. given the n number of variables you want, first define a fixed part of the variable as a cell. Here I have chosen A. Then use repmat to make a bunch of them and then use genvarname to generate unique variable names.  
n = 10;
oneVar = {'A'};
Vars = repmat(oneVar,1,n);
uniqueVars = genvarname(Vars)

uniqueVars =

  1×10 cell array

    'A'    'A1'    'A2'    'A3'    'A4'    'A5'    'A6'    'A7'    'A8'    'A9'

Third Method:
Since genvarname is going to be removed from the next release of MATLAB, as suggested, you can use the following functions:
n = 5;
S = repmat({'B'},1,n);
N = matlab.lang.makeValidName(S);
U = matlab.lang.makeUniqueStrings(N,{},namelengthmax);

So here, you have n the number of variables you want and then make the main part of the variable (B here) and repeat it n times. And then use makeValidName and makeUniqueStrings out of them.
U =

  1×5 cell array

    'B'    'B_1'    'B_2'    'B_3'    'B_4'

