|
In article <g67ugs$6bl$1@fred.mathworks.com>,
jeremy <rower15@excite.com> wrote:
>I've got the following code which is doing almost just what
>I want it to do...
> load HC_actual;
I would suggest that you get used to using the function form of load:
Matlab can do much better optimization if it doesn't have to deal with
variables in the workspace suddenly popping into existance.
You cannot (easily) use the command version of 'load' if you
are using nested functions for example.
> New_measurement = input('Enter new x/y data pair: ');
> HC_Chart_actual(end+1,:) = New_measurement;
> save HC_actual
>Now for the question... How do I put the above code in my
>M-file so that I can, from the command prompt, opt to enter
>new data or just go on with the M-file without adding new
>data to the HC_actual array?
>
>Basically, I want a Command Window prompt that asks "Do you
>want to enter new data?" and depending on whether I type in
>'y' or 'n', the program either does the above code or skips
>the code and continues the routine.
HC_struct = load('HC_actual.mat');
if ~isfield(HC_struct, 'HC_Chart_actual')
error('Corrupt HC_actual file!');
end
addsomething = input('Do you want to enter new data? Y/[N]', 's');
if ~isempty(addsomething) && strcmpi(strtrim(addsomething),'y')
New_measurement = input('Enter new x/y data pair: ');
HC_struct.HC_Chart_actual(end+1,:) = New_measurement;
save('HC_actual.mat', 'HC_struct', '-struct');
end
This code assumes that, either way, you will want HC_Chart_actual
in your workspace after the section of code. If you don't need
HC_Chart_actual unless the user wants to update it, then
you can move the load() call and associated sanity check
inside of the if statement.
--
"Ignorance has been our king... he sits unchallenged on the throne of
Man. His dynasty is age-old. His right to rule is now considered
legitimate. Past sages have affirmed it. They did nothing to unseat
him." -- Walter M Miller, Jr
|