Problem with using addvars
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sara Nasir
le 10 Juin 2022
Commenté : Peter Perkins
le 13 Juin 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');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1027395/image.png)
2 commentaires
dpb
le 10 Juin 2022
Modifié(e) : dpb
le 10 Juin 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
le 13 Juin 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.
Réponse acceptée
Cris LaPierre
le 10 Juin 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!