Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab gui files in a package?

I am trying to put some .fig and their corresponding .m files in package.

I have:

 +ui/mainWindow.fig
 +ui/mainWindow.m

But when I try to run mainWindow.fig Matlab prints an error from GUIDE:

  Error using feval
  Undefined function or variable mainWindow

The funny thing is that if i call with its fully qualified name:

 ui.mainWindow

the window appears normally (but all callbacks don't work anyway).

I have tried to import ui.* before running it.

Please note that I want to do this as sort of namespace. I don't want to have my entire application in the global scope of Matlab.

like image 309
dynamic Avatar asked Dec 11 '12 17:12

dynamic


1 Answers

Explanation

The fundamental problem is that MATLAB GUIDE is unaware of packages. Normally, it manages the callback names automatically, keeping the .m and .fig files synchronized, and everyone is happy. When the figure is within a package, it fails to properly update the callbacks in the .fig properties - these still point to the unqualified name mainWindow rather than the correct ui.mainWindow. Subsequently, all callbacks fail.

Workarounds

Two ways around this one:

  • Export your figure: Guide -> File -> Export. Place this file within your +ui folder. Open the file, and do a find-replace replacing all instances of @(hObject,eventdata)mainWindow with @(hObject,eventdata)ui.mainWindow.

  • Alternatively, you can manually update the references directly within GUIDE itself, without exporting. For each button and element, Right Click -> Property Inspector then edit the 'Callback' field, replacing mainWindow with ui.mainWindow.

Personally, I prefer the first solution because you can replace all occurrences with a single find-replace command.

like image 104
supyo Avatar answered Nov 07 '22 20:11

supyo