How do I add lines in a text file in a specific location using MATLAB ?

조회 수: 48 (최근 30일)
MatQuestion
MatQuestion 2017년 1월 17일
답변: fhz 2019년 11월 24일
Hi,
How do I add lines in a text file in a specific location using MATLAB ? For example, assume this is the text file I am reading into MATLAB
Sample line 1
Sample line 2
Sample line 3
Sample line 4
Interested location
Sample line 5
I want to add 'New sample line' right above the 'Interested location' so that my resulting file will be,
Sample line 1
Sample line 2
Sample line 3
Sample line 4
New sample line
Interested location
Sample line 5
____________
Is this possible?
Thanks,
Varshini
  댓글 수: 1
Adam
Adam 2017년 1월 17일
Read it in, add the line, write it out again. What aspect of it is causing a problem?

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

답변 (2개)

Wilson A N
Wilson A N 2017년 1월 20일
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 1월 20일
I have posted longer explanations in the past, but they come to the above: best is to copy from input to output until you have a change to make, then write the change to output, then copy the rest of the input to output

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


fhz
fhz 2019년 11월 24일
Hi
You may check my Matlab to LaTeX Library
I updated it with the following funciton: fc_lib_latex_string_add_lines.
This function I created to insert a given string into another given string at the lines given by a numeric vector. When I saw your question I remebered my solution and updated the package.
It is not dependent of LaTeX to work. It is only in the same library because it helps me to wirte LaTeX reports directly from Matlab.
Unfortunately, you have to give the numbers of line you want to insert your strings. Maybe in the future the selection of lines can be done with a different rule.

카테고리

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