필터 지우기
필터 지우기

How can I extract data and values from a table and define as individual variables?

조회 수: 6 (최근 30일)
I have a table of thousands of entries and shown in image. What I need to do is for every time 'Node #' is read on column 1 I need to extract its value from column 2 independent variable for every Node. The end goal of this is to for example, have a variable for every Node that way I can enter something like "Node2", and will get a matrix that reads all of the values of Node 2 for this data.. so therefore in this case it would be Node2 = [15.0209 30.0417 ... etc]. I'd like to automate this for every node for the entirety of the table (maybe this is what a loop is, I'm not familiar with this). Please let me know if I can provide any further information. Thank you.
Also FYI this data is extracted from ADINA FEA software if anyone has experience with this.
  댓글 수: 2
Stephen23
Stephen23 2016년 8월 1일
편집: Stephen23 2016년 8월 1일
Why?
Why not just use the table ?
Magically creating variables in a workspace is a bad idea (no matter how much beginners like to dream it up), and should be avoided if you want to learn how to write efficient, readable, and robust code:
According to the table documentation you can simply do this when the table has rowNames defined:
T2 = patients({'Adams','Brown'},:)
In your case you might find it easiest to convert the first column into rownames, then accessing the data will be as simple as:
your_table('node_name',:)
Peter Perkins
Peter Perkins 2016년 8월 3일
The row names in a table must be unique, so that won't work.
Ignacio, you haven't said what you really need to do. If your goal is to eventually create summary statistics of ZReaction grouped by Node, for example, there are better, simpler ways to do that without pulling everything out of the table. See varfun and groupby/splitapply.
If you really want to create workspace variables, you should first convert Node to categorical. Then you can pull out each node's values as something like:
node1 = t.ZReaction(t.Node == 'Node 1');
etc. Actually, your table has those "grouping" rows in it with things like 'Time 1.' etc. that don't really even belong there, so you'd probably have to deal with that first.
Here's what I'd do:
>> t
t =
Node ZReaction
____ _________
't1' 0
'n1' 1.8339
'n2' -2.2588
'n3' 0.86217
't2' 0
'n1' -1.3077
'n2' -0.43359
'n3' 0.34262
>> t2 = t([2:4 6:8],:)
t2 =
Node ZReaction
____ _________
'n1' 1.8339
'n2' -2.2588
'n3' 0.86217
'n1' -1.3077
'n2' -0.43359
'n3' 0.34262
>> t2.Time = repelem(t.Node([1 5]),[3 3])
t2 =
Node ZReaction Time
____ _________ ____
'n1' 1.8339 't1'
'n2' -2.2588 't1'
'n3' 0.86217 't1'
'n1' -1.3077 't2'
'n2' -0.43359 't2'
'n3' 0.34262 't2'
>> t3 = unstack(t2,'ZReaction','Node')
t3 =
Time n1 n2 n3
____ _______ ________ _______
't1' 1.8339 -2.2588 0.86217
't2' -1.3077 -0.43359 0.34262

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by