If the value name (baz in this case) does not contain spaces, you can do something like
FOR /F "skip=4 tokens=2,*" %%A IN ('REG.exe query "HKLM\software\foo\bar" /v "baz"') DO set "MATLABROOT=%%B"
If the name is dynamic and known only at runtime, you will need to use tokens = * and parse %% A looking for "REG_" so you know where the data starts ...
source share