<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Aptech &#187; Answers for "How can I create a new matrix where each element has a constant value?"</title>
	<atom:link href="http://www.aptech.com/questions/how-can-i-create-a-new-matrix-where-each-element-has-a-constant-value/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aptech.com</link>
	<description></description>
	<lastBuildDate>Fri, 08 Feb 2013 19:12:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>By: aptech</title>
		<link>http://www.aptech.com/questions/how-can-i-create-a-new-matrix-where-each-element-has-a-constant-value/#answer-2630</link>
		<comments>http://www.aptech.com/questions/how-can-i-create-a-new-matrix-where-each-element-has-a-constant-value/#answer-2630#comments</comments>
		<pubDate>Fri, 30 Nov 2012 21:20:27 +0000</pubDate>
		<dc:creator>aptech</dc:creator>
		
		<guid isPermaLink="false">http://www.aptech.com/questions/how-can-i-create-a-new-matrix-where-each-element-has-a-constant-value/#answer-2630</guid>
		<description><![CDATA[You have a few choices on how to initialize a matrix where each element is equal to some constant value. Which you choose will depend upon your program and which seems most clear to you. Here are a few methods &#8230; <a href="http://www.aptech.com/questions/how-can-i-create-a-new-matrix-where-each-element-has-a-constant-value/#answer-2630">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>You have a few choices on how to initialize a matrix where each element is equal to some constant value. Which you choose will depend upon your program and which seems most clear to you.</p>
<p>Here are a few methods to initialize a 2&#215;4 matrix in which each element of the new matrix is equal to 17.</p>
<p>1. Use the <tt>ones</tt> or <tt>zeros</tt> functions:</p>
<pre>
const_val = 17;
new_mat = const_val * ones(2, 4);
</pre>
<p>2. Use the <tt>reshape</tt> function:</p>
<pre>
const_val = 17;
new_mat = reshape(const_val, 2, 4);
</pre>
<p>3. If you will know a particular value at compile time (meaning before any variables are assigned values), the you can use <tt>#define</tt> and the <tt>let</tt> statement.</p>
<pre>
#define CONSTVAL 17
#define NROWS 2
#define NCOLS 4
let new_mat[NROWS, NCOLS] = CONSTVAL;
</pre>
<p>You do not have to use all uppercase characters with the <tt>#define</tt> statement. However, it is a common convention to do so. It is helpful when reading code, because if you see a variable in all uppercase that is a strong hint that it is probably a <tt>#define</tt>&#8216;ed value.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aptech.com/questions/how-can-i-create-a-new-matrix-where-each-element-has-a-constant-value/#answer-2630/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.aptech.com @ 2013-02-09 01:49:27 --