how to store value in variables of one column in cell array from another column in cell array?
9 views (last 30 days)
Show older comments
Aakriti Srivastava
on 29 Jun 2022
Commented: Aakriti Srivastava
on 25 Jul 2022
The problem is something like this:
V_table =
8×4 table
Variable lb initial_val ub
_____________ ____ ___________ ____
{'Lser_B7Tx'} 0 0.4 2
{'Lser_B7Rx'} 0 0.4 2
{'QCsmd' } 30 70 80
{'QLemb' } 30 60 80
{'Lshu_B7' } 0 4 10
{'fQ' } 2000 2500 3000
{'Cshu_B7' } 0 0.01 2
{'QLsmd' } 30 60 80
This is code I am using for what I try to achieve i.e. to store the values such as 0.4,0.4,....(initial_value) to variables Lser_B7Tx', 'Lser_B7Rx'......'QLsmd'.
for i = 1:length((V_table.Variable)
V_table.Variable{i} = V_table.initial_val{i}
V_table.Variable
end
But I am getting the error : Error using nport_B7DPX (line 125)
Brace indexing is not supported for variables of this type.
Would anyone please let me know how can I assign value to the variables of cell array
Accepted Answer
Voss
on 29 Jun 2022
% your V_table:
V_table = table( ...
{'Lser_B7Tx';'Lser_B7Rx';'QCsmd';'QLemb';'Lshu_B7';'fQ';'Cshu_B7';'QLsmd'}, ...
[0;0;30;30;0;2000;0;30], ...
[0.4;0.4;70;60;4;2500;0.01;60], ...
[2;2;80;80;10;3000;2;80], ...
'VariableNames',{'Variable','lb','initial_val','ub'})
Instead of making a bunch of different variables in your workspace that contain all the same information of what's already in the table, you can redefine your table slightly, so that the Variable column is the RowNames of the table:
V_table.Properties.RowNames = V_table.Variable;
V_table.Variable = []
Then you can get easily whatever you need, by indexing with a row name and a column name:
V_table{'fQ','lb'}
V_table{'QLsmd','initial_val'}
V_table{'QCsmd','ub'}
15 Comments
Voss
on 25 Jul 2022
There's a backslash missing before the last w you added. I included that backslash, and I removed the tokens because it doesn't seem like you need them. Does this do what you want now?
data = { ...
'PORT 23 P=1 Z=50'
'PORT 12 P=2 Z=50 PIN_ID=CB7TX'
'PORT 13 P=3 Z=50 PIN_ID=CB7RX'
'PORT 14 P=4 Z=50 PIN_ID=CB66TX'
'PORT 15 P=5 Z=50 PIN_ID=CB25TX'
'PORT 16 P=6 Z=50 PIN_ID=CB25RX'
'PORT 22 P=7 Z=50 PIN_ID=CB66RX'
};
port_match3 = regexp(data, ...
'PORT\s+\d+\s+\w+=\d+\s+\w+=\d+\s\w+=\w+','match')
port_match3{:}
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!