Error when trying to open Functional tab

Hey Brainstorm developers,
We've been running into an issue displaying previously localized intracranial electrodes through the Brainstorm functional tab over the last week. Specifically, after starting up Brainstorm without issue then clicking on the functional tab we run into the following error arising from the MATLAB built-in sortrows:
image

The error persists even after running "brainstorm reset", reloading two different protocols, and loading backups of these protocols that could previously be opened. I have also tried updating and reinstalling Brainstorm to no avail.

We're running the MATLAB version of brainstorm on a Ubuntu system. Let me know if you need any more information to help diagnose the issue.

Thanks for your help in advance!

This bug is probably related with some new database search functionalities that were added recently:
https://neuroimage.usc.edu/brainstorm/Tutorials/PipelineEditor#Search_Database

Which version of Matlab are you using?

Make sure that you don't have another toolbox in your Matlab path that includes a function "sortrows.m" that shadows the Matlab function: type "which sortrows" in the Matlab command window, it should return something in a Matlab subfolder (eg. .../MATLAB/R2019a/toolbox/matlab/datafun/sortrows.p)

For debugging this problem further, could you try the follwing:

  • type edit sortrows.m
  • put a breakpoint at line 46 (click on the little bar next to the line number)
  • refresh the display to generate the error (press F5 or go to the anatomy view and back to the functional view)
  • when the debugger stops, copy-paste the line 46 into the Matlab command window to execute it manually
  • if it works, click on the button "Run" or "Resume" to resume the execution
  • it if shows a red error message (the same as the one you posted):
    • go to the calling function (sort_nat) with the drop-down menu in the debugger toolbar,
    • type comp in the Matlab command window, copy-paste the console output here
    • go to the calling function (node_create_study) with the drop-down menu in the debugger toolbar, type uniqueComments and {sStudy.Data.Comment} in the Matlab command window, copy-paste the console output here
  • You may have to repeat this multiple times until you get the error: The same function node_create_study.m is called repeatedly for creating each data folder in the database explorer.

@MartinC Do you have any other suggestion?

Thanks for the detailed reply, Francois!

We are using MATLAB R2016a and the built-in 'sortrows.m' is the only function with that name in the path.

You were right that this was a problem with the version of MATLAB we have installed. Earlier versions of sortrows.m did not handle empty arrays elegantly. uniqueComments was an empty list (A poor reflection on our note-taking habits, perhaps?), which caused the error. New versions of sortrows.m would return empty lists instead. Putting a if ~isempty(comp) statement around line 90 in sort_nat.m fixed the problem.

Cheers!

Hi, thank you for the report!

You seem to be encountering an edge case of the natural sort function we have taken from the Matlab central (sort_nat.m), which we added recently to sort trial groups: DB: Sort all folders and trial groups in numerical order · brainstorm-tools/brainstorm3@4a7f6ea · GitHub

However, in my tests it does handle empty arrays correctly, even in older Matlab versions. To make sure the issue is not coming from something else, do you mind posting the intermediate values François requested:

  • go to the calling function (sort_nat) with the drop-down menu in the debugger toolbar,
  • type comp in the Matlab command window, copy-paste the console output here
  • go to the calling function (node_create_study) with the drop-down menu in the debugger toolbar, type uniqueComments and {sStudy.Data.Comment} in the Matlab command window, copy-paste the console output here

If we can't narrow down the issue further we could make the changes you suggested in sort_nat.m. However since this is an external function, it would be best to confirm the issue so we can report back to its author.

Thanks!
Martin

Here are the requested variables, Martin:

comp = [] at sort_nat: line 90.
uniqueComments = Empty cell array: 0-by-1 at node_create_study: line 142.
{sStudy.Data.Comment} = {} at node_create_study: line 142.

Does sort_nat break for empty cell arrays in your tests?

I also tried applying a similar if ~empty(uniqueComments) statement to node_create_study: line 142 but there were other parts of the brainstorm code that ran into similar the same problem with sort_nat (i.e. node_create_db_studies: line 168).

Cheers!

Thank you for the values, I had tried those in my tests already and sort_nat did not break for empty cell arrays on both Matlab 14b and 16b, so this issue might be specific to 16a. I do not have it installed but I guess I'll install it on my end to try. What OS are you on?

Thanks!
Martin

Interesting. I am on Ubuntu 18.04.4 LTS.
I think I now have reached the bottom of this.
Line 45 of MATLAB/R2016a/toolbox/datafun/sortrows.m is basically if ~ismatrix(x); throw error. This was calling Fieldtrip's ismatrix function rather than MATLAB's (part of their compatibility functions for earlier MATLABs), where empty arrays return zeros (whereas MATLAB's returns ones).
Sorry for wasting your time on my lab's poor path management.
Thanks so much for your help.

That makes a lot of sense, glad you figured it out!

Best,
Martin