How to draw a cube with nested for loops?
4 次查看(过去 30 天)
显示 更早的评论
Hello all,
I'm trying to draw a cube, however need help figuring out what algorithm would be.
So far I have:
function [ cubic ] = Cube( sideLength )
%UNTITLED12 Summary of this function goes here
% Detailed explanation goes here
for i = 1:sideLength
cubic = sideLength
fprintf('+', sideLength)
end
I need to write a function that will take one integer and print it like this:
a. Example 1.
>> cube(2)
+----+
|\ \
| +----+
+ | |
\| |
+----+
b. Example 2.
>> cube(4)
+--------+
|\ \
| \ \
| +--------+
| | |
+ | |
\ | |
\| |
+--------+
3 个评论
Cedric
2017-10-6
编辑:Cedric
2017-10-6
Yes but you surely tried more than this loop that does not even use FPRINTF correctly.
Show us that you made some effort.
Try to split the approach in a series of small steps:
- Am I able to print just a '+'? Yes/no, if no I read the doc of FPRINTF, look for examples online, etc.
- Am I able to repeat '-' a given number of times? Yes/no, if no I google repeat elements in MATLAB, I read about REPELEM or REPMAT and train.
- Using this, am I able to print a horizontal edge without the '+'? ...
- .. and what about one with the '+'?
- Using this, am I able to print a row of vertical edges of just a square for starting? ...
- ...
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!