How do I create a box in Matlab?

조회 수: 44 (최근 30일)
Cassandra Dooner
Cassandra Dooner 2021년 4월 15일
편집: Cassandra Dooner 2021년 4월 15일
Hi, I'm working on a little project where I need to make shapes that are able to rotate and be turned in gif/animation. In my class we have been using the box command, however I can't get it to work. When I run some the examples that we were given in class, they run, but when I change the numbers to fit what I need, it just doesn't work. This is what I have:
function boxtry3000
global Nx Ny Nz d color
Nx=100;
Ny=100;
Nz=100;
d=false(Ny,Nx,Nz);
coloe=char(zeros(Ny,Nx,Nz));
box(20,80,1,25,1,25,true,'k');
preview
model_gen
movefile('model.obj','boxtry3000.obj')
model_animate
movefile('model.gif','boxtry3000.gif')
end
I set up the function like we learned to, set the space domain, and attempted creating my 3D box that I'm looking for.
When I run it, I get this as an error;
I'm not sure how there's too many inputs, I have the x min and max, y min and max, z min and max, no hole, and the color.
What am I doing wrong?
  댓글 수: 1
the cyclist
the cyclist 2021년 4월 15일
It is infinitely better to paste code rather than images of code, which force us to re-type what you have.
You can either post code (and use the CODE format), or upload a *.m file.

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

답변 (2개)

the cyclist
the cyclist 2021년 4월 15일
편집: the cyclist 2021년 4월 15일
I don't think the box command does what you think it does. Maybe you intended rectangle?

Jan
Jan 2021년 4월 15일
편집: Jan 2021년 4월 15일
box is a built-in Matlab command. It seems, like your teacher has shadowed this function with his own function. This is a bad programming practice and it can stop other toolbox functions from working.
I assume that you havbe stored the new "box" function in a folder, which is appended on the bottom of the path (where it does not cause collisions), while your teacher added the folder on top of the path (bad!). Check this:
which box -all
The version inside Matlab's toolboxes should appear on top.
The solution is easy: Rename your "box" function, e.g. in "drawBox".
The original box command accepts 1 or 2 input arguments: doc box

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by