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

9 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Voss
Voss il 29 Giu 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 Commenti
Voss
Voss il 25 Lug 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 = 7×1 cell array
{0×0 cell} {1×1 cell} {1×1 cell} {1×1 cell} {1×1 cell} {1×1 cell} {1×1 cell}
port_match3{:}
ans = 0×0 empty cell array
ans = 1×1 cell array
{'PORT 12 P=2 Z=50 PIN_ID=CB7TX'}
ans = 1×1 cell array
{'PORT 13 P=3 Z=50 PIN_ID=CB7RX'}
ans = 1×1 cell array
{'PORT 14 P=4 Z=50 PIN_ID=CB66TX'}
ans = 1×1 cell array
{'PORT 15 P=5 Z=50 PIN_ID=CB25TX'}
ans = 1×1 cell array
{'PORT 16 P=6 Z=50 PIN_ID=CB25RX'}
ans = 1×1 cell array
{'PORT 22 P=7 Z=50 PIN_ID=CB66RX'}

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Tag

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by