How to replace the array data in workspace data?

7 次查看(过去 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.

采纳的回答

Sajid Afaque
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
  1 个评论
Sadiq Akbar
Sadiq Akbar 2023-1-16
Thanks alot dear Sajid Afaque for your kind response. Yes I do accept whenever my problem is solved. And yes this solved my problem. So I am not only accepting it but also giving you vote. Well done and thanks once again.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by