필터 지우기
필터 지우기

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
Walter Roberson
Walter Roberson 2012년 9월 30일
delt(i,j) would be (i==j)

댓글을 달려면 로그인하십시오.

추가 답변 (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