필터 지우기
필터 지우기

Replace a string in a file with a 1D array but in multiple lines

조회 수: 2 (최근 30일)
H R
H R 2016년 1월 4일
답변: Walter Roberson 2016년 1월 6일
Hi all,
Please help me with this question. I have been trying to find a simple way to do so.
I have a 1D number array with N numbers say A=[1,2,3,4,5,6,7,8,9,10,...100]; I have a text file 'Test.txt'. Inside the text file I have a string [$1].
Data
[$1]
/
How to replace the string [$1] with the content of the array A in such a way that the array content is written one after each other in multiple lines where only 6 space-delimited numbers are printed in each line except the last line that could be shorter than 6 numbers (depending on the size of A). After this I would like to save the file with other name say 'Test1.txt' with the following contents:
Data
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
...
/
  댓글 수: 4
Walter Roberson
Walter Roberson 2016년 1월 6일
H H comments
"I think the idea of having a forum is to learn not to repeatedly close the others' question without enough care to the learners. Maybe the other members are willing to help."
Walter Roberson
Walter Roberson 2016년 1월 6일
If that other answer was not what you were looking for, then say so there, instead of opening a new question.
You ask a question, someone proposes a solution, you reply there about what portions of the proposed solution meet your needs and what does not. You hold a conversation.
You do not just ask the question again, leaving the old one sitting -- all the more so without even acknowledging the previous responses, incorporating the good parts, and talking about why the other parts do not work for you.
When you open a Question, keep the discussion of the topic there in the same Question. Do not open a new Question unless it is for a different topic. Sometimes in processing a question you realize that what you had originally asked is not what you needed and you need a different question; if so then it is fine to open a new Question (especially if you refer to the old one and talk about the difference), but as long as you are still talking about the same thing then stay in the same Question.
Remember, someone has to go around and clean up the incomplete questions, pruning the duplicates, merging discussions together, cross-referencing, checking to see whether the question was solved or still needs a reply, adding appropriate Tags, updating links to resources (and help pages) that have moved, and otherwise maintain the Answers Forum as a useful place for people to come and do research in. Someone has to be the Janitor. Including closing duplicate questions to focus the discussion in one place instead of spreading it out over multiple places.
This is not a Free Consulting resource, this is a collaborative resource: the volunteers respond in public not only to answer the person who asked most immediately but also to place the solution and discussion "on the record" so that other people can find it and learn from it. And that means that we do not always arrange matters to be the most convenient for the person asking any one question: we sometimes need to manage the way questions are asked, and the topics accepted for discussion. Otherwise the Forum gets unmanageable as a resource.

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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 1월 6일
This is a duplicate question. It has been answered in the original http://uk.mathworks.com/matlabcentral/answers/262498-replace-a-string-by-a-cell-array-in-a-text-file

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by