Locate and extract values from one array to another

Hi guys, hope you doing well.
I have an array "data3" (113208576x3) with the variables "x", "y", "conc". I need to exctract from this array all the values where the "x" and "y" match an other array "SensorILM" i have (2001x4).
This is the code i tried:
load("November.mat");
load("Sensor_ILM.mat");
XILM = SensorILM.X;
YILM = SensorILM.Y;
idXmod = find(data3(:,1) == XILM)
idYmod = find(data3(:,2) == YILM)
I got the following error: "Arrays have incompatible sizes for this operation".
Do you know other way or method to do is or how to fix this error?
Thank you for your help!
Edit: I'm sorry but i didn't explain very well what i need. I want to extract the full rows of the array "data3" where the "x" and "y" match the "x" and "y" of the other array.

 Respuesta aceptada

Use ismember() or (more likely) ismembertol(). Without knowing what the data and references look like, I'll have to leave that up to you, though the use of find() is likely not necessary. The output of ismember()/ismembertol() will be a logical array that can be used directly for indexing.
Simple example:
data = 10*rand(10,2)
data = 10×2
5.0026 9.1988 5.4673 9.2215 5.5367 6.0779 8.3047 0.9583 5.8055 7.4507 3.7809 1.6238 2.7563 3.3842 0.2377 7.9529 4.0360 3.0219 0.3630 6.5546
xref = [1 2 3 4];
yref = [5 6 7 8];
tol = 0.02; % read documentation, reduce as needed
xextracted = data(ismembertol(data(:,1),xref,tol),1)
xextracted = 4.0360
yextracted = data(ismembertol(data(:,2),yref,tol),2)
yextracted = 2×1
6.0779 7.9529

5 comentarios

Thank you for your help, but i think i didnt explain the problem well. I need to extract the rows where "x" and "y" are a match, not only the "x" or the "y". I need to extract the full row where they are a match. Is it possible to adapt your code to this need?
Something like this:
data = 10*rand(10,2)
data = 10×2
1.6580 6.2993 8.1438 2.9961 5.0073 6.1667 4.0667 4.7934 3.9078 0.6150 2.3632 9.1348 0.9471 6.5049 3.6317 1.9066 9.6043 2.1395 3.9564 5.9058
xref = [1 2 3 4];
yref = [5 6 7 8];
tol = 0.02; % read documentation, reduce as needed
% these are logical arrays
xmask = ismembertol(data(:,1),xref,tol);
ymask = ismembertol(data(:,2),yref,tol);
mask = xmask & ymask;
% use as indices into data
xextracted = data(mask,1)
xextracted = 3.9564
yextracted = data(mask,2)
yextracted = 5.9058
Hey, sorry for the late reply.
The script you suggested it's not working very well for my needs. The "x" and "y" extracted are not correct. I suspect it is because of the tolerance, i reduced the most i can (if i reduce more it starts to give me an empty array) and its extracting more values than the ones i have. Any tips?
Thank you
DGM
DGM el 2 de Jun. de 2022
In order to know what goals aren't being met, it would help to have a brief example of some data which doesn't work as expected.
I already solved the problem, your suggestion is working. Thank you for your help and patience

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Etiquetas

Preguntada:

el 26 de Mayo de 2022

Comentada:

el 2 de Jun. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by