"the first block of function generates error". And we are supposed to guess what the error is? When you get an error always post the full error message.
Possibly the problem is the way you call whos. If you're giving it the name of a mat file, you need to tell whos that it is a file with the syntax:
whos('-file', chosefile)
Or possibly the problem is that you're assuming that the output of whos is a cell array of strings whereas it is a structure with several fields, so maybe:
vars = whos('-file', chosefile');
set(handles.endlist, 'String', {vars.name});