I *think* this is what you are trying to do . . .
string $visPanel[]=`getPanel -vis`;
int $mode;
if (size($visPanel)>0){
for ($panel in $visPanel){
if (`match "^modelPanel" $panel`=="modelPanel"){
$mode=`isolateSelect -q -state $panel`;
if ($mode>0){
isolateSelect -state 0 $panel;
isolateSelect -loadSelected $panel;
}
else{
isolateSelect -state 1 $panel;
isolateSelect -addSelected $panel;
}}}}
BTW . . I found the solution by looking up the example code in the MEL command referece, then dispite the fact that I did not know what the hell it was doing, I just played around with it in the script editor til I found the missing essential part that was not contained in the code you had listed . . . . The MEL command reference is a great place to look if you have a problem, because it gives you example code demonstrating how the command works . . . in this case however, their code did not work, but I was still able to extract what I needed from it to get some results . . .
"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche