Clear Filters
Clear Filters

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

3 views (last 30 days)
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);
  8 Comments
Christopher Kube
Christopher Kube on 29 Sep 2012
Edited: Christopher Kube on 29 Sep 2012
No. It did all go on one line when I cope/paste from my post here. However, when I copy/paste from the text file, it appears line by line in the m-file.
Image Analyst
Image Analyst on 29 Sep 2012
Yep - all on one line for me too, pasting directly from Answers. But no crash.

Sign in to comment.

Accepted Answer

Jan
Jan on 29 Sep 2012
Edited: Jan on 29 Sep 2012
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.
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!