3 views (last 30 days)

I have this code we are trying to run to create vectors from n closest points. However, it seems to be getting too complicated. Can someone help us to have a cleaner, more efficient code given the attched file (fpep.mat)? Below is the current code. Thanks in advance for your help.

close all;

clearvars;

% load('F_points.mat');

load('fpep.mat');

n = 10;

for pt = 1 : 953

dist = sqrt((fpep(:,7)-fpep(pt,7)).^2 + (fpep(:,8)-fpep(pt,8)).^2);

[~, ascendIdx] = sort(dist); % Not really sure what this does or why there is a ~ used here. Can someone explain this?

xyNearest(pt,:,:) = fpep(ascendIdx(1:n),7:8);

adirector_x(pt,:,:) = ([fpep(ascendIdx(1:n),1) - xyNearest(pt,:,1)]);

adirector_y(pt,:,:) = ([fpep(ascendIdx(1:n),2) - xyNearest(pt,:,2)]);

bdirector_x(pt,:,:) = ([fpep(ascendIdx(1:n),3) - xyNearest(pt,:,1)]);

bdirector_y(pt,:,:) = ([fpep(ascendIdx(1:n),4) - xyNearest(pt,:,2)]);

cdirector_x(pt,:,:) = ([fpep(ascendIdx(1:n),5) - xyNearest(pt,:,1)]);

cdirector_y(pt,:,:) = ([fpep(ascendIdx(1:n),6) - xyNearest(pt,:,2)]);

ascendIdx(ascendIdx==pt) = []; %remove the source point. Not sure why the open brackets are used here. Can someone explain this?

end

chordx = ([xyNearest(:,:,1) - fpep(:,7)]);

chordy = ([xyNearest(:,:,2) - fpep(:,8)]);

chord = sqrt((chordx).^2 + (chordy).^2);

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 6 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_758911

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_758911

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_758962

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_758962

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_758970

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_758970

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_758985

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_758985

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_759009

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_759009

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_759127

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486708-can-someone-help-us-with-choosing-the-best-syntax-and-nomenclature-for-this-code#comment_759127

Sign in to comment.