Problem with using addvars
2 ビュー (過去 30 日間)
古いコメントを表示
I want to add two more columns i.e. 191 and 192 which should have the data of column 190 (sensitivity_thold_189) and rename the variables as sensitivity_thold_190 and sensitivity_thold_191 respectively.
I am using addvars for this purpose but the problem is I am getting four columns instead of two columns.
Here ind1 is representing 4 .csv files because I have to do the same thing for all the four .csv files table SensitivityThold .
% sensitivity th
z7Acolnames.sensitivity_th = z7Acol_names (contains(z7Acol_names,'sensitivity_thold'));
% z7Acolnames.sensitivity_th(end+1) = z7Acolnames.sensitivity_th(end);
% z7Acolnames.sensitivity_th(end+1) = z7Acolnames.sensitivity_th(end);
for k = 1:length(z7Acolnames.sensitivity_th)
z7AsensorDataList(ind1).dynamicSensorData.SensitivityThold(:,z7Acolnames.sensitivity_th(k)) = z7Adata(ind1).matfiletable(:,z7Acolnames.sensitivity_th(k));
end
z7AsensorDataList(ind1).dynamicSensorData.SensitivityThold = addvars(z7AsensorDataList(ind1).dynamicSensorData.SensitivityThold,...
z7AsensorDataList(ind1).dynamicSensorData.SensitivityThold.sensitivity_thold_189,...
'After','sensitivity_thold_189');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1027395/image.png)
2 件のコメント
dpb
2022 年 6 月 10 日
編集済み: dpb
2022 年 6 月 10 日
very, Very, VERY hard code to try to read/parse -- the variable names are far too long and complex to be able to scan the code easily -- that makes for such long and complex lines debugging is difficult at best. "Simplify, simplify..."
for k = 1:length(z7Acolnames.sensitivity_th)
We can't run your code for lack of inputs, and with the above about readability I didn't try to parse too much, but the above has to be at least four elements alone just from the small piece of the table the image shows; if the result is four, then one must presume the other columns are named something different, but the above loop; if nothing else is wrong, will add four variables (at least).
Peter Perkins
2022 年 6 月 13 日
It looks like maybe you have a four-element struct array z7AsensorDataList with one field dynamicSensorData, each field element containing a table. You can do that, but seems like it might be overkill unless there's other information you have not provided.
In any case, I think Cris has the right answer.
採用された回答
Cris LaPierre
2022 年 6 月 10 日
I would do it this way
z7AsensorDataList(ind1).dynamicSensorData.SensitivityThold.sensitivity_thold_190 = z7AsensorDataList(ind1).dynamicSensorData.SensitivityThold.sensitivity_thold_189;
z7AsensorDataList(ind1).dynamicSensorData.SensitivityThold.sensitivity_thold_191 = z7AsensorDataList(ind1).dynamicSensorData.SensitivityThold.sensitivity_thold_189;
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!