Thread Subject: Help appending entered values to an array

Subject: Help appending entered values to an array

From: jeremy

Date: 23 Jul, 2008 02:18:01

Message: 1 of 3

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!

Subject: Help appending entered values to an array

From: Rodney Thomson

Date: 23 Jul, 2008 03:28:02

Message: 2 of 3

"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

Subject: Help appending entered values to an array

From: jeremy

Date: 23 Jul, 2008 18:34:04

Message: 3 of 3

Thanks for the input Rod... Your suggestion worked on the
first try.

Now here's a follow-up...

The first few lines of my file are as follows:

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com