Path: news.mathworks.com!not-for-mail
From: "Rodney Thomson" <readmore@iheartmatlab.blogspot.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help appending entered values to an array
Date: Wed, 23 Jul 2008 03:28:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 42
Message-ID: <g668g2$36g$1@fred.mathworks.com>
References: <g664cp$mjd$1@fred.mathworks.com>
Reply-To: "Rodney Thomson" <readmore@iheartmatlab.blogspot.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216783682 3280 172.30.248.38 (23 Jul 2008 03:28:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 23 Jul 2008 03:28:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1430350
Xref: news.mathworks.com comp.soft-sys.matlab:481134



"jeremy " <rower15@excite.com> wrote in message
<g664cp$mjd$1@fred.mathworks.com>...
> I am a rather new user to the MATLAB world and I am having
> some difficulty figuring this out.  
> 
> I have a mat-file that contains an array of 2 cols and 14
> rows.  When this mat-file is loaded, it produces a variable
> called "hc_actual" which is a 14x2 double.
> 
> Here's what I want to do...
> 
> Add code to my M-file that will allow me to enter a new X,Y
> pair at the command window prompt, append that pair to the
> first empty row in the "hc_actual" array, and then save the
> mat-file.  Then the M-file can continue on without
> interaction and produce all my plots, etc.  
> 
> Could someone help me come up with the code that allows me
> to append the X,Y pair to the array?  
> 
> Thanks!
> 

You can index past the end of the array and Matlab will
dynamically resize it for you:

load hc_actual.mat

hc_actual = rand([14 2]);

new_value = [2.3123 4.6631];

hc_actual(end+1, :) = new_value; % appends to end of
hc_actual - now a 15x2 matrix

save hc_actual


Rod

--
http://iheartmatlab.blogspot.com