How to replace the array data in workspace data?

1 view (last 30 days)
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.

Accepted Answer

Sajid Afaque
Sajid Afaque on 16 Jan 2023
Edited: Sajid Afaque on 16 Jan 2023
%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 Comment
Sadiq Akbar
Sadiq Akbar on 16 Jan 2023
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!