-1

I have a struct like this mesh.m_1_0.Deformation_Entformung;

the second field is a struct from m_1_0 till m_3_5 in 6 steps;

the Deformation_Entformung is a matrix with 6 columns and 325562 rows, whereby the first 3 columns contain coordinates (x,y,z).

Now I'm interested in the coordinates that are the closest to (33.5 -88.7801,-0.4480).

This is my code:

SNames = fieldnames(mesh); % SName = m_1_0,m_1_5...m_3_5  
    for loopIndex = 1:numel(SNames) 
            stuff = mesh.(SNames{loopIndex}).Deformation_Entformung; 

            mesh.(SNames{loopIndex}).('Deformation_Entformung_Koordi')=...
            stuff(min(stuff(:,1)-33.5) & min(stuff(:,2)--88.7801) & ...
            min(stuff(:,3)-0.4480), :);
    end

The code runs, but the problem is that the answer is always the first row of the matrix Deformation_Entformung. I would be glad, if someone could give me a hint.

Joshua
  • 40,822
  • 8
  • 72
  • 132
Tweets
  • 1
  • 2
  • Sorry I do not get the question. Would you mind editing the question explaining for us stupid people who do not understand? – patrik Sep 03 '15 at 13:25

1 Answers1

0

Well, first of all you mix up indices with values. min(stuff) returns the minimal value of stuff. So when you write stuff(min(stuff)) that's certainly not doing what you want it to do.

Secondly, if min(stuff(:,1)-33.5) would actually return an index (which it doesn't), then the index would be the same whether you searched for min(stuff(:,1)+100) or min(stuff(:,1)-500000). So the program would still not be doing what you want it to do.

Additionally, the way you are trying to search for the closest point does not even work from a mathematical point of view (even if your programming had no errors). The closest point is not necessarily the closest in each single coordinate. For example, [1 1 1] is certainly closer to [0 0 0] than [20 0 0], [0 20 0] and [0 0 20]. But it is not the closest one in each single coordinate. In fact it is not the closest one in any coordinate.

There might be even more issues with your code, but for starters you should work on how to determine distances. After you master that you should try to pick points with minimal distance. And only after you master both of these should you try to integrate everything into the rest of your stuff. No point in trying to do everything at once.

michael_0815
  • 146
  • 5