<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607</link>
    <title>MATLAB Central Newsreader - Converting Matrix Dimensions?</title>
    <description>Feed for thread: Converting Matrix Dimensions?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 17 Jan 2009 21:54:02 -0500</pubDate>
      <title>Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622291</link>
      <author>Jens Doe</author>
      <description>I have a problem in my class and the data is given in a 20x4 data file. It asks to find the mean, median and other things. However we're not allowed to use the mean function to find the mean. I have an idea that by converting the matrix into a 1x80 and then adding the sum and dividing by 80, I'll get the answer. But how do you convert the matrix from 20x4 to 1x80? Thanks</description>
    </item>
    <item>
      <pubDate>Sun, 18 Jan 2009 01:00:04 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622306</link>
      <author>Sadik </author>
      <description>&quot;Jens Doe&quot; &amp;lt;jerald29@hotmail.com&amp;gt; wrote in message &amp;lt;gktk1p$7ak$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a problem in my class and the data is given in a 20x4 data file. It asks to find the mean, median and other things. However we're not allowed to use the mean function to find the mean. I have an idea that by converting the matrix into a 1x80 and then adding the sum and dividing by 80, I'll get the answer. But how do you convert the matrix from 20x4 to 1x80? Thanks&lt;br&gt;
&lt;br&gt;
Hello Jens,&lt;br&gt;
&lt;br&gt;
Let us call your data matrix as dataMatrix. Then, the following will give the 1x80 version of your data:&lt;br&gt;
&lt;br&gt;
dataMatrix(:).'&lt;br&gt;
&lt;br&gt;
Please note the transpose opearation (.'). I wrote the apostrophe with a period in front in case your data is complex. However, if it is real, then dataMatrix(:)' gives the same result [that is, with only an apostrophe.].</description>
    </item>
    <item>
      <pubDate>Sun, 18 Jan 2009 15:57:01 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622352</link>
      <author>Jos </author>
      <description>&quot;Jens Doe&quot; &amp;lt;jerald29@hotmail.com&amp;gt; wrote in message &amp;lt;gktk1p$7ak$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a problem in my class and the data is given in a 20x4 data file. It asks to find the mean, median and other things. However we're not allowed to use the mean function to find the mean. I have an idea that by converting the matrix into a 1x80 and then adding the sum and dividing by 80, I'll get the answer. But how do you convert the matrix from 20x4 to 1x80? Thanks&lt;br&gt;
&lt;br&gt;
In general, the function RESHAPE is designed to, well, reshape an array. If you want to end up with a vector (N-by-1 or 1-by-N shapes) use reshape with an empty argument, or you can use the colon operation (followed by a transpose)&lt;br&gt;
&amp;nbsp;&lt;br&gt;
Example: reshape(A,[],1) will reshape an array A into a column vector&lt;br&gt;
&lt;br&gt;
hth&lt;br&gt;
Jos</description>
    </item>
    <item>
      <pubDate>Mon, 19 Jan 2009 00:26:01 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622404</link>
      <author>Jens Doe</author>
      <description>Thank you for your help so far. However, I can not get either of these two codes to work. I'll post my code for both&lt;br&gt;
&lt;br&gt;
using (:).'&lt;br&gt;
&lt;br&gt;
numbers=input('What data file would you like to load? ','s')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;load(numbers)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;numbers(:).'&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;allnumbers=numbers(:).'&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;length(allnumbers)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;l=length(allnumbers)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp(['Length of data ' num2str(l)])&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;sum(allnumbers)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;s=sum(allnumbers)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;mean=s/l&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;disp(['Your mean is ' num2str(mean)])&lt;br&gt;
&lt;br&gt;
Two things that are wrong with this. It says that the length of the data is 10 instead of 80 and it says the sum is 915 instead of 6477. &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Then using the reshape(A,[],1)&lt;br&gt;
&lt;br&gt;
clear&lt;br&gt;
clc&lt;br&gt;
&lt;br&gt;
data=input('What file would you like to load? ','s')&lt;br&gt;
&lt;br&gt;
load(data)&lt;br&gt;
&lt;br&gt;
a=reshape(data,[],1)&lt;br&gt;
&lt;br&gt;
disp(['Length of data ' num2str(a)])&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
With this I'm getting an error of &lt;br&gt;
??? Error using ==&amp;gt; horzcat&lt;br&gt;
CAT arguments dimensions are not consistent.&lt;br&gt;
&lt;br&gt;
I'm not too sure whats wrong with either.</description>
    </item>
    <item>
      <pubDate>Mon, 19 Jan 2009 00:43:01 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622405</link>
      <author>Sadik </author>
      <description>&quot;Jens Doe&quot; &amp;lt;jerald29@hotmail.com&amp;gt; wrote in message &amp;lt;gl0hap$83m$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Thank you for your help so far. However, I can not get either of these two codes to work. I'll post my code for both&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; using (:).'&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; numbers=input('What data file would you like to load? ','s')&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     load(numbers)&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     numbers(:).'&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     allnumbers=numbers(:).'&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     length(allnumbers)&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     l=length(allnumbers)&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     disp(['Length of data ' num2str(l)])&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;    sum(allnumbers)&lt;br&gt;
&amp;gt;    &lt;br&gt;
&amp;gt;    s=sum(allnumbers)&lt;br&gt;
&amp;gt;    &lt;br&gt;
&amp;gt;    mean=s/l&lt;br&gt;
&amp;gt;    &lt;br&gt;
&amp;gt;    disp(['Your mean is ' num2str(mean)])&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Two things that are wrong with this. It says that the length of the data is 10 instead of 80 and it says the sum is 915 instead of 6477. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Then using the reshape(A,[],1)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; clear&lt;br&gt;
&amp;gt; clc&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; data=input('What file would you like to load? ','s')&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; load(data)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a=reshape(data,[],1)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; disp(['Length of data ' num2str(a)])&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; With this I'm getting an error of &lt;br&gt;
&amp;gt; ??? Error using ==&amp;gt; horzcat&lt;br&gt;
&amp;gt; CAT arguments dimensions are not consistent.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'm not too sure whats wrong with either.&lt;br&gt;
&lt;br&gt;
Hello Jens,&lt;br&gt;
&lt;br&gt;
For the first method, please make sure that you are loading the correct file. It seems that you are not loading the original data which is 20x4. &lt;br&gt;
&lt;br&gt;
For the second method, yes, it will give error. This is because, given that it will load the same thing with 10 elements, your vector a will be 10x1 and you would not be able to concatenate a 10-element vector with a row string. This should help:&lt;br&gt;
&lt;br&gt;
disp(['Length of data ' num2str(length(a))])&lt;br&gt;
&lt;br&gt;
Hope this helps.</description>
    </item>
    <item>
      <pubDate>Mon, 19 Jan 2009 00:47:01 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622406</link>
      <author>Matt Fig</author>
      <description>There is a problem here.  What you are assigning to the variable 'numbers' is not the data stored in the file, but the name of the file.&lt;br&gt;
If your file name is pizza, then the variable 'numbers' holds the character string 'pizza' which you are then performing your analysis on.  You need to address the variables stored in the data file, not the name of the file.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
G^=EFe;M:WGGLWE99?WDGGWLHL@%=9F1QWMW|^Wq9GA@w:=N;9WC9HA9D=@</description>
    </item>
    <item>
      <pubDate>Mon, 19 Jan 2009 01:22:02 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622408</link>
      <author>Jens </author>
      <description>&quot;Matt Fig&quot; &amp;lt;spamanon@yahoo.com&amp;gt; wrote in message &amp;lt;gl0ii5$ru9$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; There is a problem here.  What you are assigning to the variable 'numbers' is not the data stored in the file, but the name of the file.&lt;br&gt;
&amp;gt; If your file name is pizza, then the variable 'numbers' holds the character string 'pizza' which you are then performing your analysis on.  You need to address the variables stored in the data file, not the name of the file.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; G^=EFe;M:WGGLWE99?WDGGWLHL@%=9F1QWMW|^Wq9GA@w:=N;9WC9HA9D=@&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I understand what you're saying but Im not sure how to apply it. You're saying that in a way I'm just &quot;renaming&quot; the file. How do I fix it so that I just edit that data?</description>
    </item>
    <item>
      <pubDate>Mon, 19 Jan 2009 01:35:03 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622409</link>
      <author>Matt Fig</author>
      <description>I assume you are using Matfiles which store Matlab variables.  If so then this should work.&lt;br&gt;
&lt;br&gt;
filename=input('What data file would you like to load? ','s');&lt;br&gt;
load(filename);&lt;br&gt;
&lt;br&gt;
clear filename&lt;br&gt;
who&lt;br&gt;
numbers = input('Which variable do you want to manupulate?')&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
numbers(:).'  % The file name.&lt;br&gt;
allnumbers=numbers(:).'&lt;br&gt;
length(allnumbers)&lt;br&gt;
l=length(allnumbers)&lt;br&gt;
disp(['Length of data ' num2str(l)])&lt;br&gt;
sum(allnumbers)&lt;br&gt;
s=sum(allnumbers)&lt;br&gt;
mean=s/l&lt;br&gt;
disp(['Your mean is ' num2str(mean)])&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
7I]K?#?]]MWFAS?]?dJ@M+CkFG]]CNT?@JSFMR}d?EMMGKNLRAR?C]MCLw]</description>
    </item>
    <item>
      <pubDate>Mon, 19 Jan 2009 03:17:03 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622418</link>
      <author>Jens </author>
      <description>&quot;Matt Fig&quot; &amp;lt;spamanon@yahoo.com&amp;gt; wrote in message &amp;lt;gl0lc7$3ta$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I assume you are using Matfiles which store Matlab variables.  If so then this should work.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; filename=input('What data file would you like to load? ','s');&lt;br&gt;
&amp;gt; load(filename);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; clear filename&lt;br&gt;
&amp;gt; who&lt;br&gt;
&amp;gt; numbers = input('Which variable do you want to manupulate?')&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; numbers(:).'  % The file name.&lt;br&gt;
&amp;gt; allnumbers=numbers(:).'&lt;br&gt;
&amp;gt; length(allnumbers)&lt;br&gt;
&amp;gt; l=length(allnumbers)&lt;br&gt;
&amp;gt; disp(['Length of data ' num2str(l)])&lt;br&gt;
&amp;gt; sum(allnumbers)&lt;br&gt;
&amp;gt; s=sum(allnumbers)&lt;br&gt;
&amp;gt; mean=s/l&lt;br&gt;
&amp;gt; disp(['Your mean is ' num2str(mean)])&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Thank you for posting this. It works. Im just wondering, what do lines 4-6 of the code mean? The line that starts with clear filename and ends with numbers=input('Which variable do you want to manipulate?'). Our teacher never explained what the clear function does, and I think the who command displays what variables are present.</description>
    </item>
    <item>
      <pubDate>Mon, 19 Jan 2009 03:52:02 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622425</link>
      <author>Matt Fig</author>
      <description>&quot;Jens &quot; &amp;lt;jerald29@hotmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; Thank you for posting this. It works. Im just wondering, what do lines 4-6 of the code mean? The line that starts with clear filename and ends with numbers=input('Which variable do you want to manipulate?'). Our teacher never explained what the clear function does, and I think the who command displays what variables are present.&lt;br&gt;
&lt;br&gt;
For any Matlab function you can find out what it does by typing help function_name.  So to find out what clear does, type:&lt;br&gt;
&lt;br&gt;
help clear&lt;br&gt;
&lt;br&gt;
I cleared the variable called filename before displaying the available variables so the user would not pick that variable to run the rest of the code on.  Then, using who, I display the variable available to the user.  If a clear command is issued before the filename is taken, the only variables that should be available are the ones stored in the file just loaded.  &lt;br&gt;
An alternative approach can be had in the case when the variable stored in all of the files is the same.  For example, say you have 10 files from which to choose, each has only one variable named X.  Then there is no need for the second input request, just load the file of choice and do the operations on the variable X.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
sj,tp{ft,jyRhf%jftn?mJgt%qf%u%mf%gshztjrnyf%z%ytml~q^ufr3E%</description>
    </item>
    <item>
      <pubDate>Mon, 19 Jan 2009 15:40:40 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622527</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Matt Fig&quot; &amp;lt;spamanon@yahoo.com&amp;gt; wrote in message &lt;br&gt;
news:gl0lc7$3ta$1@fred.mathworks.com...&lt;br&gt;
&amp;gt;I assume you are using Matfiles which store Matlab variables.  If so then &lt;br&gt;
&amp;gt;this should work.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; filename=input('What data file would you like to load? ','s');&lt;br&gt;
&amp;gt; load(filename);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; clear filename&lt;br&gt;
&amp;gt; who&lt;br&gt;
&amp;gt; numbers = input('Which variable do you want to manupulate?')&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; numbers(:).'  % The file name.&lt;br&gt;
&amp;gt; allnumbers=numbers(:).'&lt;br&gt;
&amp;gt; length(allnumbers)&lt;br&gt;
&amp;gt; l=length(allnumbers)&lt;br&gt;
&amp;gt; disp(['Length of data ' num2str(l)])&lt;br&gt;
&amp;gt; sum(allnumbers)&lt;br&gt;
&amp;gt; s=sum(allnumbers)&lt;br&gt;
&amp;gt; mean=s/l&lt;br&gt;
&amp;gt; disp(['Your mean is ' num2str(mean)])&lt;br&gt;
&lt;br&gt;
Rather than doing this, I'd recommend LOADing the variables into a struct &lt;br&gt;
array, then using dynamic field name referencing to access the selected &lt;br&gt;
field of that struct array.  &quot;Borrowing&quot; some of Matt's code:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
filename=input('What data file would you like to load? ','s');&lt;br&gt;
allTheData = load(filename);&lt;br&gt;
&lt;br&gt;
% Each variable in the file that was loaded is now stored in a field of the &lt;br&gt;
struct array allTheData&lt;br&gt;
% therefore, the list of fields in allTheData is the same as the list of &lt;br&gt;
variables from the file that was loaded&lt;br&gt;
% use FIELDNAMES to extract the list of fields.&lt;br&gt;
listOfVariables = fieldnames(allTheData);&lt;br&gt;
&lt;br&gt;
disp('The variables that were loaded are:')&lt;br&gt;
disp(listOfVariables)&lt;br&gt;
&lt;br&gt;
variableName = input('Which variable do you want to manipulate?', 's');&lt;br&gt;
&lt;br&gt;
% Now use dynamic field names to extract that field from the struct &lt;br&gt;
allTheData into the variable numbers&lt;br&gt;
% If you really wanted, you could validate that variableName is actually a &lt;br&gt;
member of listOfVariables&lt;br&gt;
% by using ISMEMBER and looping back (via a WHILE loop) to ask for a &lt;br&gt;
variable name if you wanted&lt;br&gt;
% to perform some basic error checking.  I'm leaving this as an exercise to &lt;br&gt;
the reader ;)&lt;br&gt;
numbers = allTheData.(variableName);&lt;br&gt;
&lt;br&gt;
% Now you can do whatever you want with the numbers variable&lt;br&gt;
&lt;br&gt;
numbers(:).'&lt;br&gt;
allnumbers=numbers(:).'&lt;br&gt;
length(allnumbers)&lt;br&gt;
l=length(allnumbers)&lt;br&gt;
disp(['Length of data ' num2str(l)])&lt;br&gt;
sum(allnumbers)&lt;br&gt;
s=sum(allnumbers)&lt;br&gt;
themean=s/l % so as not to 'shadow' the built-in MEAN function&lt;br&gt;
disp(['Your mean is ' num2str(themean)])&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
    <item>
      <pubDate>Mon, 19 Jan 2009 16:55:19 -0500</pubDate>
      <title>Re: Converting Matrix Dimensions?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242607#622548</link>
      <author>Matt Fig</author>
      <description>Good point Steve.  While the code is a bit more 'clunky' it does avoid confusion over loaded variables and those that were in the workspace prior to running this function.&lt;br&gt;
&lt;br&gt;
Thanks.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
pVX_R]STe6`VpY\p^RRT`Z~pRSefpYJ_RVap]+R`aZewjV1^ppw`Y`R&amp;gt;`fg</description>
    </item>
  </channel>
</rss>

