I want to extract data from two different text files, textfile 1 and textfile 2 and do the following operation
row 1 =0.5*text file1(row1+row2))*(text file 2(row 2-row1))
row 2 = 0.5*text file1(row2+row3))*(text file 2(row 3-row2))+row1
For example,
row1=0.5*(5+8)*(9-6)
row2=0.5*(8+6)*(7-9)+19.5 and so on
the next value in the row should add the previously obtained sum (cummulative sum)
Values in text file 1 Values in text file 2 Expected output
5 6 19.5
8 9 5.5
6 7 -7.5
7 5 -12.5
3 4 -16.5
1 2
Is there a way to write a code without actually substituting the numbers and create a column that has the following output? All my data is in text files, so the code should extract the values from the text files and then do the calculation.
Thanks in advance

 채택된 답변

Stephen23
Stephen23 2022년 4월 1일
V1 = readmatrix('file1.txt')
V1 = 6×1
5 8 6 7 3 1
V2 = readmatrix('file2.txt')
V2 = 6×1
6 9 7 5 4 2
Z = cumsum(0.5*(V1(2:end)+V1(1:end-1)) .* diff(V2))
Z = 5×1
19.5000 5.5000 -7.5000 -12.5000 -16.5000

추가 답변 (1개)

KSSV
KSSV 2022년 4월 1일

0 개 추천

REad about the function load, it will load text file data into workspace; then use you formula on the arrays.

댓글 수: 1

BINCY BABU
BINCY BABU 2022년 4월 1일
How do I represent the rows 1, 2, 3 and so on of the text file in my equation?

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

카테고리

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

질문:

2022년 4월 1일

댓글:

2022년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by