how to store value in variables of one column in cell array from another column in cell array?

16 views (last 30 days)
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
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'})
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
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 = []
V_table = 8×3 table
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
Then you can get easily whatever you need, by indexing with a row name and a column name:
V_table{'fQ','lb'}
ans = 2000
V_table{'QLsmd','initial_val'}
ans = 60
V_table{'QCsmd','ub'}
ans = 80
  15 Comments

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by