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
"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
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.