Problem with using addvars
조회 수: 4 (최근 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!