FIND function for two different sets
Show older comments
Hello,
I have a point cloud from .las and I opened it in Matlab as .txt. Then I created M array which determines X, Y and Z coordinates. I need to find all X's and all Y's that follows formulas: i > max(X)-(i*r) & i < max(X)-(i-1)*r AND j > min(Y)+(j-1)*r & j < min(Y)+(j*r) respectively.
Here is what I have done so far. The for loop does not work but I cannot figure out how to deal with it.
[X, Y, Z] = textread('chmuratxt.txt','%f %f %f' ,1027846,'headerlines',1);
M = [X, Y, Z];
%resolution
r=0.2;
dx=max(X)-min(X);
dy=max(Y)-min(Y);
%number of raws
nr=round(dx/r);
% number of columns
nc=round(dy/r);
MZ=zeros(nr, nc);
for i=1:nr
for j=1:nc
[row,col] = find ((M(:,1), i > max(X)-(i*r) & i < max(X)-(i-1)*r)&(M(:,2), j > min(Y)+(j-1)*r & j < min(Y)+(j*r)));
end ;
end;
2 Comments
Jan
on 6 Oct 2017
@amg: Do you see, that it does not matter, where the data are coming from? So mentioning this detail takes time only.
Answers (1)
I guess, that you do not mean
i > max(X)-(i*r)
but
[maxV, maxIdx] = max(X);
i > maxIdx - (i * r)
and equivalent for the other expressions.
Or perhaps:
maxX = max(X); % Don't determine this in each iteration
minX = min(X);
dx = maxX - minX;
nr = round(dx/r); % Number of rows
...
for i = 1:nr
ix = minX + i * r;
for j = 1:nc
jx = minY + j * r;
idx = [??? Something with ix and jx ???]
[row, col] = find((M(:,1), idx));
end
end
I'm not sure.
Categories
Find more on Matrix Indexing 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!