0

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

user135172
  • 1,053

1 Answers1

2

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.

A.Γ.
  • 29,518