Hi @Thomas,
The issue you're encountering with the toStruct() method of objectTrack in MATLAB, specifically the discrepancy between the documented single-argument usage and the observed two-argument definition in `objectTrack.m`, along with the unexpected population of the `ObjectClassProbabilities` field, can be explained by a combination of factors related to versioning, potential internal code changes, and default property behavior. Here's a breakdown of the possible causes and how to approach the problem:
1. Versioning Issues and Documentation Lag:
Root Cause: It's highly probable that the documentation you're consulting doesn't perfectly align with the specific version of MATLAB you're using. MathWorks updates MATLAB regularly, and documentation updates can sometimes lag behind code changes. The introduction of the `ObjectClassProbabilities` property in R2022b, as highlighted in the provided documentation, is a key indicator of potential version-specific behavior.
Explanation: The `toStruct` method might have been modified internally to handle the new `ObjectClassProbabilities` property, potentially introducing the `keepProb` argument (even if it's not intended for direct user access). If you're using a version of MATLAB where `ObjectClassProbabilities` is a standard property, the `toStruct` method might be implicitly handling it, leading to its inclusion in the output structure.
Troubleshooting: Check your MATLAB version: Use the `ver` command in MATLAB to determine your exact version.Consult version-specific documentation: Go to the MathWorks website and find the documentation specifically for your MATLAB version. Look for release notes or changes related to the `objectTrack` class and its methods. Use the `help` command in MATLAB: Typing `help objectTrack/toStruct` in the MATLAB command window might provide more up-to-date information than the general documentation, though it might not always be comprehensive.
2. The Role of `ObjectClassProbabilities` and Default Values:
Root Cause: The `ObjectClassProbabilities` property, introduced in R2022b, has a default value of `1`. This default might be automatically included when the `toStruct` method converts the `objectTrack` object, even if you haven't explicitly set a different value. Explanation: The `toStruct` method is designed to convert all properties of the `objectTrack` object into fields of a structure. Since `ObjectClassProbabilities` is a property with a default value, it's included in the resulting structure. Behavior: If you do not specify `ObjectClassID` as a nonzero integer, then the default value of `ObjectClassProbablities` will remain as 1. Troubleshooting: Explicitly set `ObjectClassProbabilities`: If you don't want this field in your structure, try setting it to `[]` (empty array) or another appropriate value (e.g., `NaN`) when you create the `objectTrack` object. Then, see if `toStruct` still includes it. Examine the structure fields: After calling `toStruct`, carefully inspect the fields of the resulting structure to confirm whether `ObjectClassProbabilities` is present and what its value is.
3. Hidden or Internal Arguments (The `keepProb` Mystery):
Root Cause: The presence of a second argument (`keepProb`) in the `objectTrack.m` file suggests an internal implementation detail that isn't intended for public use. Explanation: MathWorks might use this argument internally for specific processing related to object tracking logic or probability management. It's possible that the argument is used in overloaded versions of the `toStruct` method or in internal calls within the `objectTrack` class. Important: You should *not* attempt to directly use or manipulate this `keepProb` argument unless you have explicit documentation from MathWorks on how to do so. Undocumented arguments are subject to change without notice and can lead to unpredictable behavior. Troubleshooting:Avoid using the second argument:Continue calling `toStruct` with only the `objectTrack` array as the argument, as per the documented usage. If errors persist:** If you encounter errors related to the argument count, it might indicate a more serious issue with your MATLAB installation or a corrupted `objectTrack.m` file. In this case, consider reinstalling the relevant toolbox or contacting MathWorks support.
4. Workarounds and Solutions:
Post-processing the Structure: The simplest and safest workaround is to remove the `ObjectClassProbabilities` field from the structure after calling `toStruct`:
tracks = objectTrack.empty(); % or however you create your array of tracks % ... populate your tracks array ... S = toStruct(tracks); S = rmfield(S, 'ObjectClassProbabilities'); % Remove the field
Creating a Custom Conversion Function: If you need more control over the conversion process, you could create your own function to extract the desired properties from the `objectTrack` objects and create the structure array manually.
Hope this helps.