<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><base href="x-msg://519/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi,</div><div><br></div><div>Replace loop with:</div><div>C = A.*B;</div><div><br></div><div>Arvid</div><br><div><div>15 nov 2012 kl. 09:21 skrev Paul Carrico <<a href="mailto:paul.carrico@free.fr">paul.carrico@free.fr</a>>:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div lang="FR" link="blue" vlink="purple" style="font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="WordSection1" style="page: WordSection1; "><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">Dear all,<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">Sorry for this basic question but I failed in finding the answer after a look in the documentation …<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">… how can I optimize the following basic code (using vectorization instead of loops) ?<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US"> </span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">Thanks to the community<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US"> </span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">Paul<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; color: rgb(50, 185, 185); ">mode</span><span lang="EN-US" style="font-family: Monospaced, serif; color: rgb(74, 85, 219); ">(</span><span lang="EN-US" style="font-family: Monospaced, serif; color: rgb(188, 143, 143); ">0</span><span lang="EN-US" style="font-family: Monospaced, serif; color: rgb(74, 85, 219); ">)</span><span lang="EN-US" style="font-family: Monospaced, serif; "><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; "> </span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; ">A</span><span lang="EN-US" style="font-family: Monospaced, serif; "><span class="Apple-converted-space"> </span><span style="color: rgb(92, 92, 92); ">=</span><span class="Apple-converted-space"> </span><span style="color: rgb(74, 85, 219); ">[</span><span style="color: rgb(188, 143, 143); ">1</span><span class="Apple-converted-space"> </span><span style="color: rgb(255, 170, 0); ">:</span><span class="Apple-converted-space"> </span><span style="color: rgb(188, 143, 143); ">0.2</span><span class="Apple-converted-space"> </span><span style="color: rgb(255, 170, 0); ">:</span><span class="Apple-converted-space"> </span><span style="color: rgb(188, 143, 143); ">100</span><span style="color: rgb(74, 85, 219); ">]</span><span style="color: rgb(92, 92, 92); ">'</span><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; ">B</span><span lang="EN-US" style="font-family: Monospaced, serif; "><span class="Apple-converted-space"> </span><span style="color: rgb(92, 92, 92); ">=</span><span class="Apple-converted-space"> </span><span style="color: rgb(74, 85, 219); ">[</span><span style="color: rgb(188, 143, 143); ">100</span><span class="Apple-converted-space"> </span><span style="color: rgb(255, 170, 0); ">:</span><span class="Apple-converted-space"> </span><span style="color: rgb(188, 143, 143); ">1</span><span class="Apple-converted-space"> </span><span style="color: rgb(255, 170, 0); ">:</span><span class="Apple-converted-space"> </span><span style="color: rgb(188, 143, 143); ">595</span><span style="color: rgb(74, 85, 219); ">]</span><span style="color: rgb(92, 92, 92); ">'</span><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; "> </span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; color: rgb(74, 85, 219); ">[</span><span lang="EN-US" style="font-family: Monospaced, serif; ">nl,nc</span><span lang="EN-US" style="font-family: Monospaced, serif; color: rgb(74, 85, 219); ">]</span><span lang="EN-US" style="font-family: Monospaced, serif; "><span class="Apple-converted-space"> </span><span style="color: rgb(92, 92, 92); ">=</span><span class="Apple-converted-space"> </span><span style="color: rgb(50, 185, 185); ">size</span><span style="color: rgb(74, 85, 219); ">(</span><span style="">A</span><span style="color: rgb(74, 85, 219); ">)</span><span style="">;</span><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; ">C</span><span lang="EN-US" style="font-family: Monospaced, serif; "><span class="Apple-converted-space"> </span><span style="color: rgb(92, 92, 92); ">=</span><span class="Apple-converted-space"> </span><span style="color: rgb(50, 185, 185); ">zeros</span><span style="color: rgb(74, 85, 219); ">(</span><span style="">nl,</span><span style="color: rgb(188, 143, 143); ">1</span><span style="color: rgb(74, 85, 219); ">)</span><span style="">;</span><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; "> </span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; color: rgb(160, 32, 240); ">for</span><span lang="EN-US" style="font-family: Monospaced, serif; "><span class="Apple-converted-space"> </span><span style="">i</span><span class="Apple-converted-space"> </span><span style="color: rgb(92, 92, 92); ">=</span><span class="Apple-converted-space"> </span><span style="color: rgb(188, 143, 143); ">1</span><span class="Apple-converted-space"> </span><span style="color: rgb(255, 170, 0); ">:</span><span class="Apple-converted-space"> </span><span style="">nl</span><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; ">   <span class="Apple-converted-space"> </span><span style="">C</span><span style="color: rgb(74, 85, 219); ">(</span><span style="">i,</span><span style="color: rgb(188, 143, 143); ">1</span><span style="color: rgb(74, 85, 219); ">)</span><span class="Apple-converted-space"> </span><span style="color: rgb(92, 92, 92); ">=</span><span class="Apple-converted-space"> </span><span style="">A</span><span style="color: rgb(74, 85, 219); ">(</span><span style="">i,</span><span style="color: rgb(188, 143, 143); ">1</span><span style="color: rgb(74, 85, 219); ">)</span><span style="color: rgb(92, 92, 92); ">*</span><span style="">B</span><span style="color: rgb(74, 85, 219); ">(</span><span style="">i,</span><span style="color: rgb(188, 143, 143); ">1</span><span style="color: rgb(74, 85, 219); ">)</span><span style="">;</span><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; color: rgb(160, 32, 240); ">end</span><span lang="EN-US" style="font-family: Monospaced, serif; "><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US" style="font-family: Monospaced, serif; "> </span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><i><span lang="EN-US" style="font-family: Monospaced, serif; color: rgb(100, 174, 100); ">// D = prod(</span></i><span lang="EN-US" style="font-family: Monospaced, serif; "><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><i><span style="font-family: Monospaced, serif; color: rgb(100, 174, 100); ">//A(nl,1)*B(nl,1) - C(nl,1)</span></i><span style="font-family: Monospaced, serif; "><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US"> </span></div></div>_______________________________________________<br>users mailing list<br><a href="mailto:users@lists.scilab.org" style="color: purple; text-decoration: underline; ">users@lists.scilab.org</a><br><a href="http://lists.scilab.org/mailman/listinfo/users" style="color: purple; text-decoration: underline; ">http://lists.scilab.org/mailman/listinfo/users</a><br></div></blockquote></div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Arvid Rosén</div><div><br></div><div>Softube AB</div></div></span>S:t Larsgatan 10c<br>SE-582 24 Linköping<br>Sweden<br>Mobile: (+46) 73 25 123 47<br>Office: (+46) 13 21 16 23<br>Fax: (+46) 13 10 00 23<br>Mail: <a href="mailto:arvid@softube.com">arvid@softube.com</a><br>URL: <a href="http://www.softube.com/">www.softube.com</a></div></span></div></span></span>
</div>
<br></body></html>