MATLAB: While trying to use assignin to define value to a variable, for some reason, the variable is not created successfully although no error message appears

assignin function

I have attached the code below. That command is at line 316. I just want to know why the variable cannot be created. Many thx.

Best Answer

In Tab_group_SellectCallback you have
TabSellectCallback(0,0,group,1);
The 1 in the fourth parameter becomes the variable num inside TabSellectCallback. The code there has
for Tab_group_temp = 1:num_group
for TabNumber_temp=1:num(Tab_group_temp)
num_group is 6, so the outer loop is 1:6, and that value is used to index num on the second of those lines. With it being possible for Tab_group_temp to be 6, it follows that the variable num must have at least 6 values. But it does not have 6 values: it is a scalar with value hard-coded as 1.
Now, Tab_group_SelectCallback is called as
Tab_group_SellectCallback(0,0,1);
where 1 is the group. At the point of that call, there is an existing variable num that contains the information that is needed on the line
for TabNumber_temp=1:num(Tab_group_temp)
but those two num are not the same variables because num is not being passed into Tab_group_SellectCallback and Tab_group_SellectCallback is calling TabSellectCallback with hard-coded scalar 1.
The repair would be to arrange to pass num into Tab_group_SellectCallback, which should then pass it into TabSellectCallback instead of the hardcoded 1.