MATLAB Answers

0

I have a txt file and i read the txt file in matlab . After reading the text file i need to change a value in some line . But the value isnt first word or number in the line. The number is to be replacd with a output value from simulink simulation.

Asked by Kumar Shivu on 15 Apr 2014
Latest activity Edited by Kumar Shivu on 15 Apr 2014
clc;
fid = fopen('summary.txt'); n = 1; textline = {}; while( ~feof(fid) ) textline(n,1) = {fgetl(fid)};
if ( n == 28 ) temp = char(textline(n));
s1 = textscan(temp ,'%s %s %s %s %d %s %s %s %s %s %s %s '); % This code reads the 28 line where want makes the changes
s2= s1(1,5); %This is the i want wanna change
s3=Omega_speed.signals.values(1); % The Output from a Simulation stored in a simout variable
textline(n,1) = {['Starting Rotary Speed = %d ',t,' 1/min (Clockwise Rotation) at Mass 7 ',temp(regexp(temp , '\s ', 'once'):end)]};
end
n = n + 1;
end
fclose(fid)
fid = fopen('summary_1.txt', 'w') % this file is created with the new data created.
for(n = 1:length(textline))
fwrite(fid, cell2mat(textline(n)));
end
fclose(fid)

  0 Comments

Sign in to comment.

0 Answers