Gistlib Logo

gistlib

write a function doubleonleft that takes a vector and a numeric index as inputs, multiplies by 2, the value of the element on the left of that referenced by index, and returns the resulting vector. in matlab

main.m
function output = doubleonleft(vec, idx)
    if idx > 1
        vec(idx) = vec(idx) * 2 * vec(idx - 1);
    end
    output = vec;
end
134 chars
7 lines

similar matlab code snippets

create a function that accepts a vector input v and a vector input i and returns the value of v indexed by i. in matlab
create a function that accepts 2 scalar inputs (a and b) and returns a vector output numbers counting by 1 from a to b. in matlab
create a function that accepts a vector input and a scalar input and returns the value of the vector indexed by the scalar. in matlab
design the function function out = mse_loss(x, y) that computes the empirical mse loss of prediction x using the true labels y, both vectors of the same length. in matlab
how to calculate the skewness of a vector in matlab
how to calculate the minimum of a vector in matlab
how to calculate the product of a vector in matlab
how to calculate the maximum of a vector in matlab
how to calculate the variance of a vector in matlab
how to calculate the range of a vector in matlab

related categories

matlab
vector
function

gistlibby LogSnag