MATLAB Answers

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.

1 view (last 30 days)
Kumar Shivu
Kumar Shivu on 15 Apr 2014
Edited: Kumar Shivu on 15 Apr 2014
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)]};
n = n + 1;
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)));


Sign in to comment.

Answers (0)

Sign in to answer this question.