How do I check for already used elements?

Problem:
Starting with an Matrix of 2 columns. First column contains starting values, second column depending values. I want to search through 3 other matrices, all of different sizes, for values that are nearest to my starting values from matrix 1. Think of it like having a vector of deformations and the depending forces the second column.
What I want to avoid ist getting double values because I simply check for nearest values:
D = {a,b,c}
V1 = d
for k = 1:size(V1,1)
dist = abs(D{i}(:,2) - V1(k,1));
minDist = min(dist);
minIdx = (dist == minDist);
minIdx = find(minIdx,1,"first");
minVal = D{i}(minIdx);
end
If I do this, I will end up getting doubled values for different starting values.
Additional Info:
Before processing the code above I start identifying my longst matrix in terms of rows, then putting every second value from the deformation column into V1 and the corresponding froces into the second column.
This is about a mechanical observation and I got 4 measurements done. I can plot force-deformation-diagrams for each one and ultimately am trying to make a diagram of an averaged curve now.
I hope you can follow my asking and I am very sorry for my bad English. Ask me anything.
Best regards,
Jan

Respuestas (1)

David Hill
David Hill el 3 de Abr. de 2022
D = {a,b,c};
v=d(:,1);
n=zeros(length(v),length(D));
for k=1:length(D)
[~,m]=min(abs(v-(D{k}(:,2))'),[],2);
n(:,k)=D{k}(m,2);%I believe this is the matrix you want
end

3 comentarios

Jan Lorenz
Jan Lorenz el 3 de Abr. de 2022
tahnk you, Sir
although this does not solve my problem, it is coded much better as far as I can tell.
This still gives me double values.
Do you have an suggestion on how to check for already used values and in case to forward to the next value? Alternativley I am trying to solve this issue by using mean of the two nearest values.
Thanks for the help!
Image Analyst
Image Analyst el 3 de Abr. de 2022
How can you tell if a value is "used" or not?
Perhaps one way would be to make an array of all nan's with the nan() function. Then assign elements. ANy remaining nan's will be "not used".
What kind of variables are a, b, and c? Why are you using cell arrays instead of regular numerical arrays?
Jan Lorenz
Jan Lorenz el 3 de Abr. de 2022
I use Cell arrays beacuse I had problems fitting my matrices into for-loops:
a, b, c and d are matrices of different sizes each containing 2 columns with forces(column 1) and deformations(column 2). Their elemtes alternate stepwise over the rows reaching a maximum in force and deformation (This is where the observed beam breaks, should have mentioned that).
I don't get how the nan() function can help?

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2021a

Preguntada:

el 3 de Abr. de 2022

Comentada:

el 3 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by