How to replace the array data in workspace data?
9 次查看(过去 30 天)
显示 更早的评论
I have three Mat files namely '2sn0dB.mat', '3sn0dB.mat' and '4sn0dB.mat'. All of them have array 0f size 100 x 1 and having same name 'one' but having different data. I want to replace the data of 'one' in 3sn0.mat and data of 'one' in 4sn0.mat but don't want to change data of 'one' in 2sn0.mat. I want to replace the data of both 'one' of 3sn0.mat and 4sn0.mat like the following:
I want to add 0.50 to the one of 2sn0.mat file such that one of 2sn0.mat is retained but replace the 'one' of 3sn0.mat with those new values.
Likewise I want to add 0.60 to the newly formed array 'one' of 3sn0.mat such that it is retained but replace the 'one' of 4sn0.mat with these recent new values.
All the three mat files are in the attachments.
0 个评论
采纳的回答
Sajid Afaque
2023-1-16
编辑:Sajid Afaque
2023-1-16
%if its possible try to convert the variables to a struct then perform the
%calculations
var1 = load('2sn0dB.mat');
var2 = load('3sn0dB.mat');
var3 = load('4sn0dB.mat');
var2.one = var1.one + 0.5; %add 0.50 to the one of 2sn0.mat
var3.one = var2.one + 0.6; %add 0.60 to the newly formed array 'one' of 3sn0.mat
save('2sn0dB','-struct','var1');
save('3sn0dB','-struct','var2');
save('4sn0dB','-struct','var3');
please do accept the answer if it solved your issue , it will help others in the community
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!