How to replace the values in a variables based upon the common field values from another variable in matlab?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Niraj Bal Tamang
am 6 Apr. 2021
Kommentiert: Niraj Bal Tamang
am 22 Apr. 2021
I have two variables 'P-idx' and 'Replacing_values'. P_idx is a bigger matrix consisiting of the FID_1 value/s from Replacing_values at different cells. Replacing_values has two fields: FID_1 and Volume. I want to replace the values of the FID_1 in the P_idx with the Volume values of Replacing_values based upon the common FID_1 values. Can anyone please help me how to do this?
0 Kommentare
Akzeptierte Antwort
Maadhav Akula
am 22 Apr. 2021
Hi Niraj,
I believe you want to replace all the values in P_idx with their corresponding Volume(based on FID_1) values from the provided struct, please check the following code snippet:
non_empty_idx = find(~cellfun('isempty', P_idx)); % Finding all the non-empty indices
for i = 1:length(non_empty_idx) % Looping through the non_empty indices and replacing them with Volume
P_idx{non_empty_idx(i)} = [network1(P_idx{non_empty_idx(i)}+1).Volume]; % Added 1 as FID_1 values started from 0 in network1
end
Hope this helps!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices 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!