Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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);

Respuesta aceptada

Mohammad Sami
Mohammad Sami el 6 de Abr. de 2021
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));

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by