Changing the value of column in a file if matches certain criteria of another value

1 回表示 (過去 30 日間)
Salim
Salim 2023 年 9 月 8 日
コメント済み: Daniel 2023 年 9 月 10 日
Hi Folks,
I am new in programming. I have 2 text files. the file xx has 4 columns and the file yy has 2 columns.
What I want to do is reading file yy and if any row mathes the values of row (column 2 and column 3) of file xx, then changes the value of column 4 in the file xx to a number 99 instead of its original value.
Thanks in advance
Salim

回答 (1 件)

Daniel
Daniel 2023 年 9 月 8 日
編集済み: Daniel 2023 年 9 月 8 日
You can approach programming problems in the same basic way as word problems in math or science.
What do you need to do? You've stated that.
What are components in that?
  1. You need to read files. You need to read xx and yy.
  2. You need to store the data from xx and yy inside the MATLAB workspace.
  3. You need to compare data in yy to data in xx.
How far have you gotten? What specifically do you need help with? Do you know how to read files into a data matrix? Do you know how to access regions of a matrix by index? Do you know how to write a for loop?
  7 件のコメント
Salim
Salim 2023 年 9 月 10 日
編集済み: Walter Roberson 2023 年 9 月 10 日
Dear @Daniel,
below is attached my trial with the .m file and the input files.
Many thanks in advance.
Salim
edge_assign
Daniel
Daniel 2023 年 9 月 10 日
Hi @Salim,
Please perform the steps in my reply https://www.mathworks.com/matlabcentral/answers/2018351-changing-the-value-of-column-in-a-file-if-matches-certain-criteria-of-another-value#comment_2879516. Once you have done so, let me know the results. The error in your code can be found by following the suggestion in my comment. Once the error is identified we can discuss how to fix it, if the solution isn't clear from my previous comments.
Regards,
Daniel

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by