Keep Variable Name when adding Variables to a table
18 ビュー (過去 30 日間)
古いコメントを表示
Hi!
I have a problem with Variable Names when adding Variables to a table. It seems odd, as it works with the "patients" example from the documentation but not with my own table and Variables. Here is a part of the code:
out.combinednew = addvars(out.combined,out.newvars.(1));
The added Variable gets the name "Var32" instead of "Q_end".
I have also tried writing one column of the table into a variable and then adding that variable to the table but it is the same problem.
Is there another way to keep the Variable Names when adding a new Variable?
0 件のコメント
採用された回答
Walter Roberson
2023 年 8 月 8 日
The relevant code is using inputname() to try to figure out variable names. inputname() returns empty for any expression giving a value, but returns the variable name in the caller if a plain unindexed variable was passed.
out.newvars.(1) is an expression that pulls out the contents of the first variable of a table, but it is not a plain unindexed variable name, so inputname will return empty.
You should use
out.combinednew = addvars(out.combined,out.newvars.(1), 'NewVariableNames', out.Properties.VariableNames(1));
2 件のコメント
Walter Roberson
2023 年 8 月 8 日
Note by the way that when you are not using the relative-position properties, that you might as well just do
out.combinednew = [out.combined, out.newvars(:,1)];
その他の回答 (1 件)
Florian Bidaud
2023 年 8 月 8 日
Hi
out.combinednew = addvars(out.combined,out.newvars.(1),'NewVariableNames','Q_end');
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!