How to replace the array data in workspace data?

조회 수: 9 (최근 30일)
Sadiq Akbar
Sadiq Akbar 2023년 1월 16일
댓글: Sadiq Akbar 2023년 1월 16일
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에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by