App desiner GUI crashes when use scatter3

14 views (last 30 days)
Davide P
Davide P on 10 Feb 2021
Commented: Davide P on 25 Feb 2021
i have a problem with app designer and scatter3.
When I use scatter3 specifying the color for each point, the app crashes without giving any errors.
This is the line that causes the app to unexpectedly close:
scatter3 (app.UIAxes_GL_3D, ROI_coord(:, 1), ROI_coord(: 2), ROI_coord(:, 3), 1, color_matrix);
ROI_coord is a matrix of 22375x3 double, color_matrix is a matrix of 22375x3 double (with values between 0 and 1), UIAxes_GL_3D is the app axis.
I tried to use fewer points and in that case everything works fine.
I use Matlab version 2020a.
Why does this happen?
Thank you,

Answers (2)

Adam Danz
Adam Danz on 10 Feb 2021
Edited: Adam Danz on 11 Feb 2021
I've reproduced the problem using Matlab Online with the code below (commented-out to discourage people from trying it). Matlab Online crashes and throws an error in Chrome: Error code: Out of Memory
But this shouldn't cause Matlab to crash. It should just throw an error. I encourage you to report the problem: Contact Us - MATLAB & Simulink
% This will crash Matlab (Matlab Online 2020b)
% ROI_coord = rand(22375,3);
% color_matrix = rand(22375,3);
% app.UIAxes_GL_3D = uiaxes();
% scatter3 (app.UIAxes_GL_3D, ROI_coord(:, 1), ROI_coord(:, 2), ROI_coord(:, 3), 1, color_matrix);
There may be other ways to plot your data that don't involve storing 22375 graphics objects. Without knowing more about the intended visualization, it's tough to make suggestions.
Update I
Without the color_matrix, the scatter plot is created without a problem.
Update II
I traced the problem in scatter3() and it crashes when the CData property is set (the color matrix). Even if you set the CData after the plot is generated, it will still crash (see below).
ROI_coord = rand(22375,3);
color_matrix = rand(22375,3);
app.UIAxes_GL_3D = uiaxes();
h = scatter3 (app.UIAxes_GL_3D, ROI_coord(:, 1), ROI_coord(:, 2), ROI_coord(:, 3), 1);
% crash here:
% h.CData = color_matrix;
Update III
None of these problems happen with Matlab r2020b (update 4) on Microsoft Windows 10.
Workaround ideas
If there is color grouping, use indexing to plot each group separately using plot3() or scatter3(). dr
You could try using color indexing rather than defining the RGB value matrix. That's covered the documentation.
If each point varies in color, you might be able to visualize the data using another form such as a controur or surface. Perhaps you could reduce the density of data and plot custers using kmeans or another clustering method.
Davide P
Davide P on 25 Feb 2021
Ok, no problem. I had to do some GUI with Matlab and actually there are often problems. We hope they improve.

Sign in to comment.

Davide P
Davide P on 18 Feb 2021
I have updates from support: has been confirmed as a bug currently present
Cause of the problem: the problem is related to the render engine "It is an internal memory issue when interacting with Chromium windows specifically, which is why the behavior is observable with Apps and UIFigures but not with the standard Java based figure."
I immediately say that the definitive solution does not yet exist. It's only partially solved in the 2021a prerelease.
There are possible wokarounds. I put them here because maybe someone could be useful for actual release.
  • In 2020a and 2020b versions: you have to try to switch to an alternative render engine, so depending on the one set, you have to try to use one of these two commands:
> from the Windows Command Prompt using:
matlab -softwareopenglmesa
> executing the following in the MATLAB Command Window:
>> opengl software
I tried with "matlab -softwareopenglmesa" and I was able to visualize the points within UIAxes. However, for me the solution is not optimal because in any case there is a heavy slowdown in the rotation of the points and above all it is an impractical solution because it depends on the PC on which the App is running.
  • In the 2021a preprelease version the problem is mitigated (but not completely solved) because it uses a different version of Chromium. Use in that case:
s = scatter3 (app.UIAxes_GL_3D, ROI_coord (:, 1), ROI_coord (:, 2), ROI_coord (:, 3), 1, color_matrix, 'PickableParts', 'none');
PickableParts was introduced in 2021 and works to mitigate the problem.
Obviously I was told that the development team will look for a definitive solution that will be included in the code as soon as it is ready.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!