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 allfid = 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); endendfclose(fid);
Best Answer