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

3 次查看(过去 30 天)
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 个评论
Christopher Kube
Christopher Kube 2012-9-29
编辑:Christopher Kube 2012-9-29
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 2012-9-29
Yep - all on one line for me too, pasting directly from Answers. But no crash.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2012-9-29
编辑:Jan 2012-9-29
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by