Re: Take out index



Nathan <ngreco32@xxxxxxxxx> wrote in message <c3448c04-efa4-463b-82c3-2e58518ba8d5@xxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On Jun 24, 3:01?pm, "Diego Lass" <dlISC...@xxxxxxxxx> wrote:
Hi
For a problem,
A = [ 1; 2; 3; 4; 5; 6; 7 ]
A =
? 1
? 2
? 3
? 4
? 5
? 6
? 7

I know that I want to add 2 to each element, expect for the entries 1:2:end
i.e. I want to get a function f()
B = f(A) such that
B =
? 1
? 3
? 3
? 6
? 5
? 8
? 7
what is the most efficient way to do this? ?Remember add 2 is just a simple example, and the vector A might be really huge

What about
A(2:2:end) = A(2:2:end)+2;
B = A;

Simple enough?

Considering as suggested by Nathan your function would be:

function Out = ArrayInc(In_array, Increment, OddEven)
% Check part (up to you)

% Engine part
if nargin == 2
Even = 1;
else
whichcase = [0,1];
IDX = strcmpi(OddEven, {'odd', 'even'});
Even = whichcase(IDX);
end

In_array(1+Even:2:end) = In_array(1+Even:2:end)+Increment;
Out = In_array;
end

The OddEven input must be string. If you write 'even', even - positioned elements in the input array wil be incremented by "Increment", else odd - positioned el.

Cheers
.



Relevant Pages

  • Re: etesters
    ... engine. ... They listed a bunch of our products without our knowing about it. ... There should 30 entries per page or so, ...
    (sci.electronics.design)
  • Re: Importing Data
    ... plify importing this dataset:http://data.giss.nasa.gov/gistemp/tabledata/GL= ... % the engine ... % the result (the last few entries only) ... but mine crashed when it get's to 2008 cause December's data point isn't a number (I was using str2num). ...
    (comp.soft-sys.matlab)
  • Explorer Question
    ... predictive text box entries on a web page. ... it annoying when typing entries into a web page or search ... engine and it prompts pre-written text entries. ... Regards ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Vector operations
    ... What's reported in idx are the indicies of B that are closest in value to the entries of A. Hope this helps in any brainstorming. ...
    (comp.soft-sys.matlab)
  • Re: Israel finally defends itself
    ... to accuse them of lying, we need to present evidence to _demonstrate_ ... engine & here's a link what I got: ... Almost 400 entries. ...
    (soc.culture.jewish.moderated)