MATLAB: Matlab crashes when I paste a long segment of code into an m-file

crasheditor

I generate a string of code which is written into a text file by the function below. I would like to run the code I have written to the text file by pasting it into an existing m-file. Upon copy/paste into an m-file Matlab unexpectedly crashes.
Any help would be appreciated. Thanks!
clc;
clear all
fid = fopen('C:\Users\Chris\Desktop\tens.txt','w');
lat = perms('ijklmn');
st = 'abcdef';
d = 'delt(';
for i = 1:length(lat)
g(i,:) = [lat(i,1) st(1,1) lat(i,2) st(1,2) lat(i,3) st(1,3) lat(i,4) st(1,4) lat(i,5) st(1,5) lat(i,6) st(1,6)];
if i == 1
cod = ['ret = ' d g(i,1) ',' g(i,2) ')*' d g(i,3) ',' g(i,4) ')*' d g(i,5) ',' g(i,6) ')*' d g(i,7) ',' g(i,8) ')*' d g(i,9) ',' g(i,10) ')*' d g(i,11) ',' g(i,12) ')+...'];
elseif i == length(lat)
cod = [d g(i,1) ',' g(i,2) ')*' d g(i,3) ',' g(i,4) ')*' d g(i,5) ',' g(i,6) ')*' d g(i,7) ',' g(i,8) ')*' d g(i,9) ',' g(i,10) ')*' d g(i,11) ',' g(i,12) ');'];
else
cod = [d g(i,1) ',' g(i,2) ')*' d g(i,3) ',' g(i,4) ')*' d g(i,5) ',' g(i,6) ')*' d g(i,7) ',' g(i,8) ')*' d g(i,9) ',' g(i,10) ')*' d g(i,11) ',' g(i,12) ')+...'];
end
if fid ~= -1
fprintf(fid,'%s\r\n',cod);
end
end
fclose(fid);

Best Answer

I can confirm this for R2009a/64/Win7. I've pasted it as multiple lines.
I have opened a new M-file in the editor. Then I've opened the same file using WordPad and inserted the code there. After saving Matlab's editor updated its display and Matlab crashed again. Re-opening Matlab did not crash, but leaves the editor window open. The last semi-colon of the pasted code is marked by M-Lint with the warning:
An M-Lint problem analyzing this file caused your previous MATLAB session to terminate unexpectedly.
(Very interesting. I'm curious where Matlab stores this information!)
Now I've created an M-Lint report for the file and I got 1440 messages about the usage of "i" and "j" as variables. Finally I've replaced them by "ii" and "jj", copied it and pasted the block to a new file - and Matlab crashed again.
Besides the obvious method to upgrade your Matlab, I suggest to use a less brute way of programming. I boldly claim without a even trying it: This function will be very slow.