How to solve type mismatch error when assigning variable to class in conditional?
Example Code:
1 flag = true;
2 if flag
3 this.prop = TFlag();
4 else
5 this.prop = FFlag();
6 end
Error Code:
Type name mismatch: TFlag ~= FFlag.
In the diagnostic report, the error is shown in line 5, where this.prop cannot be assigned FFlag() because it is understood as a varible of class type TFlag().
Question:
It appears that this.prop is being intialized as a variable of class type TFlag regardless of the condition, and I am unable to run this conditional. It should also be noted that the constructor method of each of these classes returns a struct(), but they are different sizes. TFlag returns a struct of size 30, and FFlag returns a struct of size 10.Example Code:
1 flag = true;
2 if flag
3 this.prop = TFlag();
4 else
5 this.prop = FFlag();
6 end
Error Code:
Type name mismatch: TFlag ~= FFlag.
In the diagnostic report, the error is shown in line 5, where this.prop cannot be assigned FFlag() because it is understood as a varible of class type TFlag().
Question:
It appears that this.prop is being intialized as a variable of class type TFlag regardless of the condition, and I am unable to run this conditional. It should also be noted that the constructor method of each of these classes returns a struct(), but they are different sizes. TFlag returns a struct of size 30, and FFlag returns a struct of size 10. Example Code:
1 flag = true;
2 if flag
3 this.prop = TFlag();
4 else
5 this.prop = FFlag();
6 end
Error Code:
Type name mismatch: TFlag ~= FFlag.
In the diagnostic report, the error is shown in line 5, where this.prop cannot be assigned FFlag() because it is understood as a varible of class type TFlag().
Question:
It appears that this.prop is being intialized as a variable of class type TFlag regardless of the condition, and I am unable to run this conditional. It should also be noted that the constructor method of each of these classes returns a struct(), but they are different sizes. TFlag returns a struct of size 30, and FFlag returns a struct of size 10. matlab, code generation MATLAB Answers — New Questions