Finding category/string in table and converting values

4 次查看(过去 30 天)
Alright so I'm having trouble knowing how to write a script to convert values.
Basically, I want to 1) Read in a file or Access a table 2) Find all the instances in the rows of the table with the string "CBEAM" 3) In said row, go to the 4th column and multiply that number by 0.5 4) Find all instances in the rows of the table with the string "CQUADR" 5) In said row, go to the 6th column and multiply that number by 0.6
So I can envision lots of if, then statements, which is totally fine. But I really don't know how to get started or what to write at all. Can anyone help

采纳的回答

Peter Perkins
Peter Perkins 2018-2-21
Don't do that. Assume T is your data stored in a table containing a categtorical variable named SomeVarName whose categories are 'CBEAM' 'CQUADR', ... . Then
i = (T.SomeVarName == 'CBEAM');
T.SixthVarName(i) = .5 * T.SixthVarName(i);
etc.
  3 个评论
Hao Tang
Hao Tang 2018-2-21
Thanks Steven, this works well! I didn't realize it was that simple. I'll let you know if I have any further questions later.
Hao Tang
Hao Tang 2018-2-21
Ran into an issue. So I have this 'PBEAM' info on two lines, with commas indicating new columns.
PBEAM,46,1,3.8750077499845,1.251e+00,1.251e+00,,1.001e+01,,+C1
+C1,0.9842519685,0.9842519685,-0.9842519685,0.9842519685,0.9842519685,-0.9842519685,-0.9842519685,-0.9842519685
In matlab, I can find the word 'PBEAM' go to the 4th column and replace the value by multiplying the value with a constant. However, it can't find the next line. EVEN if it did, the constant I multiply with is different, yet falls under the same column as the line above. Not sure how to solve this issue.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by