How do I create a box in Matlab?

44 次查看(过去 30 天)
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