首页 > 解决方案 > 深复制浅复制 Matlab 结构/结构字段

问题描述

嗨,我想在对mySTruct结构字段进行一些减法后更改结构。mySTruct如何在不使用(......)解决路径的情况下将我的新结构复制到其中mySTruct.KMZ我需要将结果复制到mySTructmySTruct.KMZ.Lstgn.Abkm)深度 3 的单元格中我的代码的重要部分是这个计算

currentFile = mySTruct .(subsref(fieldnames(mySTruct ),substruct('{}',{k})));
 for idx = 2 : cellRowSize
                display(idx)     
                resForLstg(idx,1) = table(currentEnergie(idx,2)-currentEnergie(idx-1,2));  
                %Res for column 2
                resForLstg(idx,2) = table(currentEnergie(idx,3)-currentEnergie(idx-1,3));        
                %Res for column 3

currentFile.Lstg.(subsref(fieldnames(currentFile.Energie),substruct('{}',{i}))) = resForLstg;

问题是这currentFile是一个新的独立结构,与 Struct 没有任何共同之处mySTruct。我的代码的最后一行发生了变化mySTruct

标签: matlabdata-structuresstructdeep-copyshallow-copy

解决方案


推荐阅读