How do I create a box in Matlab?

16 views (last 30 days)
Cassandra Dooner
Cassandra Dooner on 15 Apr 2021
Edited: Cassandra Dooner on 15 Apr 2021
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 Comment
the cyclist
the cyclist on 15 Apr 2021
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.

Sign in to comment.

Answers (2)

the cyclist
the cyclist on 15 Apr 2021
Edited: the cyclist on 15 Apr 2021
I don't think the box command does what you think it does. Maybe you intended rectangle?

Jan
Jan on 15 Apr 2021
Edited: Jan on 15 Apr 2021
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

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!