Info

This question is closed. Reopen it to edit or answer.

How to modify a particular location in a data file automatically (at each iteration) from a Simulink model output

1 view (last 30 days)
I have a Simulink drive train model that outputs a new rotational speed value at each iteration. I need to write this value at each iteration in a specific location in a data file. This data file is the input of a Fortran code(*dat file) that outputs the aerodynamic torque that my drive train model needs as input.
I tried to form two different data files: one before the rotational speed I need to modify and one after it. So, using the dos command 'copy', I did a code that first copy the first bit of data before the rotational speed I need to change. Then I write the new rotational speed value coming from my Simulink model using the function dlmwrite with the append option.
Then I used again the dos command copy to concatenate the first data file in which the updated rotational speed has been written and the second data file I already created that I do not need to modify. The problem is when I use the DOS comand to concatenate the .*dat files, it adds a space between them and the FORTRAN code is unable to run because of the space.
Is it possible to concatenate two data files without having to enter a space between them? Or is there an easier way to do want I need to do?
All i want is the rotational speed RPM output from the simulink function to be written at a fixed place in .*txt or .*dat file for an e.g I want the rpm output from simulink to be written in line 4 and spaced 5.
Many thanks
Code:
%explicitly tell Simulink engine to include the following MATLAB functions %that will be used in this function coder.extrinsic('dlmwrite','fopen','fclose','fscanf','dos','pause','sprintf','num2str','str2num')
flovawtpart1='C:\flovawt1\aero\flovawtpart1.dat' flovawtpart2='C:\flovawt1\aero\flovawtpart2.dat'
dos('copy flovawtpart1.dat flovawt.dat')
rpm=omega_r*60/(2*pi) x=num2str(omega_r) x=sprintf('%.2f',rpm) z=str2num(x)
dlmwrite('C:\flovawt1\aero\flovawt.dat',z,'delimiter','','-append');
dos('copy flovawt.dat+flovawtpart2.dat flovawt.dat')
<<C---Users--s189810--Desktop--Picture1.png>>

Answers (0)

Community Treasure Hunt

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

Start Hunting!