Hi @Gavin,
Glad to help you out again. After going through your comments and reviewing the documentation provided at the link below,
https://www.mathworks.com/help/matlab/ref/cell2mat.html
The error suggests that you are attempting to access an element of a variable using brace indexing { } but the variable does not support this operation. In MATLAB, brace indexing is used for accessing elements of cell arrays, while regular parentheses ( ) are used for accessing arrays or matrices.The function cell2mat expects a cell array where each cell contains data of the same type and dimension. If any cell contains a different type or an unsupported structure (like nested cells or objects), it will raise this warning. Here are steps listed below to identify the source of the error.
Check the Cell Array: Before calling cell2mat, inspect your cell array to ensure all cells contain compatible data types. You can do this with a loop:
for i = 1:numel(C) disp(class(C{i})); end
Use Debugging Techniques: Since dbstack isn't providing useful context here, consider adding temporary breakpoints or using try-catch blocks around your code where cell2mat is called. For example:
try A = cell2mat(C); catch ME disp(ME.message); % Optionally log or output more details about C end
Simplify Your Code: Isolate the segment of code that uses cell2mat. Create a minimal reproducible example where you suspect the error occurs and test it independently.
Example Analysis: Given your cell array example:
C = {[1], [2 3 4]; [5; 9], [6 7 8; 10 11 12]};
Running cell2mat(C) should work as all elements are numeric and can be concatenated. If you encounter issues, check if any modifications were made to C before this call.
If your data structure is complex or inconsistent, consider using alternative functions like vertcat or horzcat, which can handle concatenation without converting to a standard array.
By following these steps, you should be able to pinpoint the source of your warning and rectify any issues related to brace indexing and data compatibility in your MATLAB code.
Hope this helps.
Please let me know if you have any further questions.