How do I format adding columns to a matrix in a textfile or in general
조회 수: 1 (최근 30일)
이전 댓글 표시
So I have a matrix that I am printing to a file that looks like this
1, 2, 3;
6, 7, 8;
11,12,13;
I want to add a two column vectors of the form
[4 ;9 ;14] and [5 ;10 ;15]
to make the updated file look like
1, 2, 3, 4, 5;
6, 7, 8, 9,10;
11,12,13,14,15;
I am running a while loop to get the column vectors so I either have to update the matrix i the while loop before printing it, I dont know the code syntax to do that, or update the matrix in the file after each while loop, this seems easier to place in my code, but I don't know the syntax on how to code this. If anyone could offer help on this issue I would appreciate it. (I dont know how to format matrices in this Q&A so I apologize if this question is hard to look at).
댓글 수: 4
채택된 답변
Jess Lovering
2017년 6월 26일
If you wanted to append the file in that manner over each loop then you would have to read in each line, add to the line, and write to a new file - not a very efficient way to do it. I don't think that you can just add to the end of each line simply like you would like to do. You would be better off adding the data to your matrix in the loop and writing the file at the end. You can use the cat function to concatenate the new array to the main matrix pretty easily. Type "doc cat" at your command prompt to pull up the help on this.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!