MATLAB: How to identify variables in workspace from strings in cell arrays and then make changes to the variables themselves

cell arrayinterpolationregexpwhos

Hi all,
I have a cell array containing strings say for eg {'var1','var2','var3',….'varn'} . Now i have values of all these variables in my workspace.So what i want to do is , first to get values of these variables from workspace.Then i want to compare the lengths of these variables.If their lengths are not equal,i want to make them equal using interpolation.I am so very confused that i cant decide how to go ahead on this.Maybe i need to use regexp,whos,..but i dont know how to use them here.

Best Answer

The reason you are confused is because naming variables in this way is really not the way to solve anything. I don't know how you got the variables in the first place, maybe you individually named them all, but this is the type of problem you come to when you do that. Naming them this way in the first place is usually where people come unstuck, but even if they succeed in doing so accessing them afterwards is a real pain.
Use a struct with dynamic field names if you really want numbered items or even better just use an array - it is what they are for!