How to fix "Subscripted assignment dimension mismatch" in For loop with min/sort functions, (or other)
Show older comments
In the following code F(:,i) is being assigned different column sizes for each iteration i. The Dmin sort was my attempt at taking the smallest 2 values (I only want 2 rows for all i in F composed of the min distance (x,y) locations in X), but for instance with [1 2], [0 1], and [1 0] in pts they are all equal distance from point i=1 in X (1,1). Is there a way with the find command (or other method) to only take 2 values for F?
clc
clear all
close all
x=[1 2 3 4 5 6 7 8 9 10];
y=[1 2 3 4 5 6 7 8 9 10];
X=[x y];
pts=[0 0
3 5
1 2
0 1
1 0];
for i=1:10
D = sqrt((x(i)-pts(:,1)).^2+(y(i)-pts(:,2)).^2);
sort_minD = sort(D);
Dmin(1:2,i) = sort_minD(1:2,1);
F(:,i) = find(D<=Dmin(2,i));
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!