violinplot (R2024b): SceneNode error?

I am trying to use the violinplot function, tried the following official example
ydata = randn(100,1);
xgroupdata = categorical(repelem(["group1";"group2";"group3"],[20,50,30]));
violinplot(xgroupdata,ydata)
I get the following warning in client area:
Warning: Error in state of SceneNode.
Undefined function 'log2' for input arguments of type 'string'.
and NOTHING gets plotted in the figure!
Please help.

 Risposta accettata

The typical cause of this sort of problem, is if you have a third-party .m file with the same name as a Mathworks function.
To debug the problem, experiment with
restoredefaultpath; rehash toolboxcache
if this solves the problem then you know that something that had been added to the path was the cause. (If it does not solve the problem, try creating an empty directory and cd'ing to it and running the code again, to test out the hypothesis that something in your current directory was the problem.)

6 Commenti

The fact that it works here on Answers supports Walter's suspicion about the cause of the problem.
ydata = randn(100,1);
xgroupdata = categorical(repelem(["group1";"group2";"group3"],[20,50,30]));
violinplot(xgroupdata,ydata)
I profiled the violinplot call you showed but it does not list log2 among the functions called, further supporting Walter's hypothesis. I'd considered that maybe if the axes were already in log scale when you tried to add the violin plot to it that could have caused this warning, but it issued a different warning. [I'll note that different warning to the development staff, as it's not a very understandable warning message IMO.]
Makes sense. Getting somewhere but something strange is happening.
  • If I run the following code with startup commented, all is well.
  • If I run this code and then run startup (F9 or client area), all is well.
  • If I uncomment startup and run it all together, blank plots!
clc, clear all, close all;
restoredefaultpath; rehash toolboxcache;
ydata = randn(100,1);
xgroupdata = categorical(repelem(["group1";"group2";"group3"],[20,50,30]));
violinplot(xgroupdata,ydata)
% startup
My startup.m has quite a lot of files but I don't understand why it would matter how I run it- whether as part of the script as the next or separately.
SceneNode is used by back-end graphics. I do not know exactly what it is used for; searches for SceneNode in the source code do not show anything relevant -- but I know that it shows up, for example, for malformed legend text at the time that the legend is to be rendered (rather than the time it is defined.)
So because it is used for back-end stuff, in theory altering the MATLAB path after creating the violin plot could have an effect, if you altered the path between the time of creating the graphics and the time of fully rendering the graphics.
Your startup.m file probably contains one or more addpath calls that add a directory to the MATLAB search path that shadows a function included with MATLAB that violinplot calls. [I'm guessing it also suppresses the warning that ought to be issued if you shadow a built-in function in this way. Or even worse, it could suppress all warnings.] But without seeing what your startup.m file contains we can't be certain.
Intriguing. I have a decent sized GitHub library added to genpath in startup so it's not practical to show all functions here.
Another interesting observation which solved my problem: If I add a pause before startup, the plot remains (doesn't get blanked out). I don't think the pause time matters because even pause(0.001) worked.
Just in case anyone else wanders here wondering why their violinplots don't work: If you use the calcium imaging analysis code CaImAn (MATLAB version) or any analysis package that includes CaImAn, this code includes a function called kde() that appears to "shadow" an identically named MATLAB function as described above. Renaming the CaImAn kde function, the file name to match it, and the calling code in other CaImAn functions, allows violinplot to work again.

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by