MATLAB: Using Evalin and a Cell

evalin

Hello,
I have a cur_hdr which contains my new variable name I want to write to my workspace. I have a 3×1 cell called 'Temp'. I want my new variable name to equal temp in my workspace.
I've tried a bunch of variations such as
evalin('base',[cur_hdr '(:,1)=' temp ';']);
This gives me
??? Error using ==> horzcat CAT arguments dimensions are not consistent.
When I try something such as x = temp
I don't have a problem. I'm simply trying to reassign variables.
thanks in advance

Best Answer

Your expression [cur_hdr '(:,1)=' temp ';'] needs to construct a string, but your variable "temp" is not a string.
For your purposes you should use assignin() instead:
assignin('base', cur_hdr, temp);