How can I write a function that gives out a matrix with the specified rows and columns?
이전 댓글 표시
Write a function getfancyrectangle(R,C) that takes the number of rows and columns and returns a string as a character matrix, containing a "fancy" rectangle filled with alternating '@' and '#' characters.
For example:
R=2
C=3
@#@
#@#
댓글 수: 2
Jan
2014년 10월 27일
This is obviously a homework question. As usual we will not solve it for you, such that you keep the chance to submit a solution without cheating.
Better post, what you have tried so far and ask a specific question.
S
2014년 10월 28일
편집: per isakson
2014년 10월 28일
답변 (2개)
Jan
2014년 10월 27일
A hint:
n = 10;
x = repmat(1, 1, n);
x(2:2:n) = 2;
per isakson
2014년 10월 28일
편집: per isakson
2014년 10월 28일
Your function as of the comment works nicely
>> s = getfancyrectangle( 4, 5 )
s =
@#@#@
#@#@#
@#@#@
#@#@#
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!