Defining Functions in MATLAB Snippet

Hi everyone,

Till now my MATLAB Snippet has been functioning well until I recently defining a function in the script editor. For e.g.

% In the script editor inside the MATLAB Snippet configuration window

kIn_cell = dataset2cell(kIn);

% some code here

kIn_cell_new = add_cell(kIn_cell);

 

% Defining the function

function kIn_cell_new = add_cell(kIn_cell)

% Code defining the function

end

 

When I run the code, I received the error of "Function definition is misplaced or improperly nested.". After I open the temporary .m file, I found out that the snippet is using a try/catch statement, and my own function is not allowed to be defined inside this control statement as a nested function.

How do I solve this problem? Is there anyway I can define my functions elsewhere? I urgently need a solution, thanks!

Regards,

Eugene

I can't test this right now as MATLAB scripting isn't working at all for me, but what happens if you save your function definition in a .m file?

If necessary, your MATLAB script can start by adding the location of that file to the search path using addpath. If you really want you could probably even have the KNIME workflow generate and save the .m file before calling the MATLAB script.

Hi Tom,

thanks for your comment. Yes, I have already saved the functions in seperate files and added them to the search path. At least everything is working right now, just that I have to make sure that when some other people want to open the KNIME workflow, they must also have the .m files :)

Regards,

Eugene

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.