0
$\begingroup$

below there is a task we were asked to do using matlab. I wrote this function below which works fine. But, since 'for' loops were not shown yet in the course, I think that the instructor meant doing it without loops. Any ideas? Thanks!

By the way, How do I make new line in stackexchange editor? Thanks!

enter image description here Question 2

$\endgroup$
2
$\begingroup$

Given $m$, $n$ you can assign

$A(1:2:m,1:2:n)=1;$

$A(2:2:m,2:2:n)=1;$

P.S. Loops in MATLAB are in general slow, substitute it if possible by vector/matrix operations that MATLAB is optimized for.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.