Hello, I have to write a code that will do what the following question asks. I am very confused on how to do this.
'You will want to add up all of the vectors in the file called "Random_Data.txt", but in addition, you want to save all of the intermediate results. For example, once you add up the first two vectors, write the results into another text file called "Results.txt". The next line should have the intermediate answer of adding the previous result to the third vector, etc... Your Results.txt should contain vector_count - 1 vectors with the final vector being the final answer for adding all of the vectors up in the Random_Data.txt file.
Example:
Original File:
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Results.txt
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
any help is much appreciated!

댓글 수: 2

Jan
Jan 2017년 3월 7일
What is your question?
John BG
John BG 2017년 3월 7일
first steps learning encryption?

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

답변 (1개)

Walter Roberson
Walter Roberson 2017년 3월 7일

0 개 추천

The quick way is to use cumsum() and write out the 2nd row to the end row.

댓글 수: 2

Dewey Phillips
Dewey Phillips 2017년 3월 8일
편집: Walter Roberson 2017년 3월 8일
i tried this code and it did not work.
B = cumsum(my_ans)
C = B([2:end],:)
fprintf(fileID, '%d/t%d/t%d/t%d/t%d/n', C')
Walter Roberson
Walter Roberson 2017년 3월 8일
\t and \n not /t and /n

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

카테고리

도움말 센터File Exchange에서 Text Data Preparation에 대해 자세히 알아보기

질문:

2017년 3월 7일

댓글:

2017년 3월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by