Error using horzcat Dimensions of arrays being concatenated are not consistent.
Show older comments
n=20;
xleft = -100;
xright = 100;
yfront = 0;
yback = 200;
step = 1;
[x,y] = meshgrid(xleft:step:xright,yfront:step:yback);
faces = delaunay(x,y);
a=0;
for i=xleft:step:yback
a = a+1;
b = 0;
for j=yfront:step:yback
b = b+1;
if i>-10 && i<50 &&i>30 &&j<50
z(a,b) = 15;
else
z(a,b) = 0;
end
end
end
vertices = [x(:) y(:) z(:)];
orig = [0 0 20];
%dir = [-10 20 -2];
vert1 = vertices(faces(:,1),:);
vert2 = vertices(faces(:,2),:);
vert3 = vertices(faces(:,3),:);
4 Comments
KSSV
on 6 Oct 2020
Check the sizes of x, y, z..they are not same so error.
NOTE: Don't attch your code as image snippet. You should copy paste here.
YINGNAN SUN
on 6 Oct 2020
KSSV
on 6 Oct 2020
The dimensions of x, y, z are 201*201, 201*201, 301*201 respectively.....so you cannot join them..
YINGNAN SUN
on 6 Oct 2020
Answers (1)
Walter Roberson
on 6 Oct 2020
for i=xleft:step:yback
That is dubious, especially considering
for j=yfront:step:yback
what happened to xright ?
[x,y] = meshgrid(xleft:step:xright,yfront:step:yback);
for j=yfront:step:yback
Technically speaking, it is not guaranteed that the colon operator in a for loop will give exactly the same values as the colon operator that you used in your meshgrid call. You should do something like
xvec = xleft:step:xright;
yvec = yfront:step:yback;
[x, y] = meshgrid(xvec, yvec);
and later
for i=xvec
for j = yvec
Your double for loop can be optimized away as
a = zeros(size(x));
a( x>-10 & x<50 & y>30 & y<50) = 30;
with no loop at all.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!