Replacing table cell elements based on values of other table elements
Ältere Kommentare anzeigen
There is a call-array table such as:
type node rank
____ ________ ____
'abc' '3 0' ','
'acd' '0 3' ','
'bcd' '0 3' ','
'aaa' '3 2' ','
'abb' '4 2' ','
'baa' '4 0' ','
'ccc' '0 2' ','
'caa' '2 1' ','
'cdd' '0 1' ','
'csd' '1 0' ','
'css' '3 1' ','
'bff' '0' ','
'gre' '2 2' ','
'hhh' '3' ','
'qwe' '1' ','
'pin' '3' '1'
'pin' '2' '2'
'pin' '4' '3'
'pin' '1' '4'
The size of table.node{1} is 1x3 cell array. It is not a 1x2 array. Table is using bar | as delimiter.
I need to change non zero node values based the rank of their corresponding pin (listed in the last rows of the table). In other words, I need something similar to:
For any non-zero table.node cell element, find the corresponding index of table.type==pin and change the table.node cell element with table.rank{index}
The table should become:
type node rank
____ ________ ____
'abc' '1 0' ','
'acd' '0 1' ','
'bcd' '0 1' ','
'aaa' '1 2' ','
'abb' '3 2' ','
'baa' '3 0' ','
'ccc' '0 2' ','
'caa' '2 4' ','
'cdd' '0 4' ','
'csd' '4 0' ','
'css' '1 4' ','
'bff' '0' ','
'gre' '2 2' ','
'hhh' '1' ','
'qwe' '4' ','
'pin' '1' '1'
'pin' '2' '2'
'pin' '3' '3'
'pin' '4' '4'
What is the shortest command to do this?
5 Kommentare
Andrei Bobrov
am 20 Sep. 2019
"The size of table.node{1} is 1x3 cell array. It is not a 1x2 array."
Please attach mat-fale where your table is stored.
S H
am 20 Sep. 2019
Agnish Dutta
am 5 Feb. 2020
Bearbeitet: Agnish Dutta
am 5 Feb. 2020
I'm unable to fully comprehend what you've asked for. I'm not sure what you mean by "table.type == pin". Could you kindly exlpain this more lucidly with an example of a particular row?
Also, please see if the following documentataion link helps:
Add delete and re-arrange table variables: https://www.mathworks.com/help/matlab/matlab_prog/add-and-delete-table-variables.html
S H
am 7 Feb. 2020
Agnish Dutta
am 7 Feb. 2020
Would it be ok to split this table into two i.e. create a separate table for the "pin" rows first for your use case?
Antworten (1)
S H
am 7 Feb. 2020
0 Stimmen
Kategorien
Mehr zu Reporting and Database Access finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!