I want to develop a 3D cubes systematically from 5x5x5 to 15x15x15 with the increments of 1.I developed below code.But there is a problem in the way I am giving the inputs of x,y,z with the increments.
x=5:1:15;
y=5:1:15;
z=5:1:15;
B=zeros(x,y,z);
for i =1:x;
for j=1:y;
for k=1:z;
if ((j==1)|(j==y))&((k==1)|(k==z));
B(i,j,k)=1;
else B(i,j,k)=0;
if((i==1)|(i==x))&((k==1)|(k==z));
B(i,j,k)=1;
else B(i,j,k)=0;
if ((i==1)|(i==x))&((j==1)|(j==y));
B(i,j,k)=1;
else B(i,j,k)=0;
end
end
end
end
end
end
Error
Error using zeros
Size inputs must be scalar.
Error in (line 6)
B=zeros(x,y,z);

 채택된 답변

madhan ravi
madhan ravi 2020년 7월 25일

0 개 추천

B = zeros(numel(x), numel(y), numel(z)); % error is gone but I have no idea what’s going on

댓글 수: 3

Hege
Hege 2020년 7월 25일
편집: Hege 2020년 7월 25일
x=5:1:15; is not equal to the numel(x).same for the y and z.
could you please tell me why I am getting the error called' Error using zeros. Size inputs must be scalar' for the below first code.
x=5:1:15;
y=5:1:15;
z=5:1:15;
B=zeros(x,y,z);
And If Give the inputs like below no errors.But I want to simplify the code.
x=5,6,7,8,9,10,11,12,13,14,15;
y=5,6,7,8,9,10,11,12,13,14,15;
z=5,6,7,8,9,10,11,12,13,14,15;
B=zeros(x,y,z);
madhan ravi
madhan ravi 2020년 7월 25일
편집: madhan ravi 2020년 7월 25일
for x = x
for y = y
for z = z
zeros(x, y, z)
end
end
end
doc zeros
Hege
Hege 2020년 7월 25일
Thank you sir.I got the answer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2017a

태그

질문:

2020년 7월 25일

댓글:

2020년 7월 25일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by