필터 지우기
필터 지우기

How to replace the values of a column of a variable with another column from another variable in matlab?

조회 수: 2 (최근 30일)
I have two variables 'network' and 'sedsource'. I used the following code to produce the 'input' variable which contains 1 value for the common cells between the two variables and 0 for the others. Now i want to replace these 1 with the 'Volume' field values from the 'sedsource' variable such that the common cells have the volume values while the others are 0. Can anyone please help me with this?
Thank You
b = [network.FID_1];
a = [sedsource.FID_Networ];
Linknum = ismember(b,a);
Link=Linknum';
input = double(Link);

채택된 답변

Mohammad Sami
Mohammad Sami 2021년 4월 6일
You can do as follows if you want to maintain it as struct array.
b = [network.FID_1];
a = [sedsource.FID_Networ];
[lib,loca] = ismember(b,a);
Vol = cell(size(network));
Vol(lib) = {sedsource(loca(lib)).Volume};
Vol(~lib) = {0};
[network.Volume] = Vol{:};
Alternatively convert your data into a table.
network = struct2table(network);
sedsource = struct2table(sedsource);
[lib,loca] = ismember(network.FID_1,sedsource.FID_Networ);
network.Volume = zeros(height(network),1);
network.Volume(lib) = sedsource.Volume(loca(lib));

추가 답변 (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