The problem with Alamakanambra's solution is that it will unify multiple '\n' into a single '\n'
For example if this is your code:
y=eye(5)
x=eye(5)
% set m
m = length(x)
% display value of m
fprintf('value of m is: %d', m)
And you would like to remove this line: y=eye(5)
Then running the previous solution will output the following code:
x=eye(5)
% set m
m = length(x)
% display value of m
fprintf('value of m is: %d', m)
The desired output is:
x=eye(5)
% set m
m = length(x)
% display value of m
fprintf('value of m is: %d', m)
The solution is to use the CollapseDelimiters property, and set it to false in the strsplit method
You can find the solution here
This is the full solution:
currentEditor = matlab.desktop.editor.getActive;
originalSelection =currentEditor.Selection;
row = originalSelection(1)-1;% get row of cursor
C = strsplit(currentEditor.Text,'\n','CollapseDelimiters',false) % Split text of editor by lines
C(row) = [];%remove current row
currentEditor.Text = strjoin(C,'\n');%join it together
currentEditor.Selection = [originalSelection(1)-1 1 originalSelection(1) 0 ];
% make sure cursor is on the same line and on first position