Problem with using addvars
6 views (last 30 days)
Show older comments
Sara Nasir
on 10 Jun 2022
Commented: Peter Perkins
on 13 Jun 2022
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');
2 Comments
dpb
on 10 Jun 2022
Edited: dpb
on 10 Jun 2022
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
on 13 Jun 2022
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.
Accepted Answer
Cris LaPierre
on 10 Jun 2022
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 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!