Array shift operation. The following script defines and displays a ten-element y array. The script should shift the y array “to the right” by one index, set the first element of the y array to y_new, and display the result. Find the error in the script.

y = 0:10;
y
y_new = -1;
y(2:length(y))= y(1:length(y));
y(1) = y_new;
y


Solution
y = 0:10;
y
y_new = -1;
y(2:length(y))= y(1:length(y)-1); % <-
%<- A(I) = B, the number of elements in B and I must be the same.
y(1) = y_new;
y

Trades & Technology

You might also like to view...

When is valve float more likely to occur?

A. high engine speeds B. low engine speeds C. engine rated speeds D. engine lugdown

Trades & Technology

Pythium blight devastation is associated with:

A) low humidity and high temperatures B) high humidity and low temperatures C) ?high humidity and high temperatures D) low temperatures and low humidity

Trades & Technology

The term ____________________ refers to a specific locus on a chromosome, usually encoding a gene

Fill in the blank(s) with correct word

Trades & Technology

A ____________________ uterus has no uterine horns and a single large uterine body

Fill in the blank(s) with correct word

Trades & Technology