How to replace the array data in workspace data?

9 Ansichten (letzte 30 Tage)
Sadiq Akbar
Sadiq Akbar am 16 Jan. 2023
Kommentiert: Sadiq Akbar am 16 Jan. 2023
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.

Akzeptierte Antwort

Sajid Afaque
Sajid Afaque am 16 Jan. 2023
Bearbeitet: Sajid Afaque am 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 Kommentar
Sadiq Akbar
Sadiq Akbar am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by