# How to create a vector with the same value in matlab

### How do you repeat a value in a vector in Matlab?

u = repelem( v , n ) , where v is a scalar or

**vector**, returns a**vector**of**repeated**elements of v . If n is a scalar, then each element of v is**repeated**n times. The length of u is length(v)*n .### How do I create an array of the same number in Matlab?

Accepted Answer

You can try using ‘ones’ function to **create** such a matrix. Following is an example to **create** a matrix X=[300,300,300,300,300,300,600,600,600,600,600,600] X=[300*ones(1,6),600*ones(1,6)];

### How do I concatenate a vector in Matlab?

You can also use square brackets to join existing matrices together. This way of creating a matrix is called

**concatenation**. For example,**concatenate**two row**vectors**to make an even longer row**vector**. To arrange A and B as two rows of a matrix, use the semicolon.### What is a concatenated vector?

**Vector Concatenate**, Matrix

**Concatenate**.

**Concatenate**input signals of same data type to create contiguous output signal.

### How do you call a function in Matlab?

**Calling Functions**- Open Live Script.
**MATLAB**® provides a large number of**functions**that perform computational tasks. - ans = 5. If there are multiple input arguments, separate them with commas:
- ans = 1×3 10 6 5. Return output from a
**function**by assigning it to a variable: - maxA = 5.
- [maxA,location] = max(A)
- location = 3.
- hello world.
- clc.

### What is a function in Matlab?

A

**function**is a group of statements that together perform a task. In**MATLAB**,**functions**are defined in separate files.**Functions**can accept more than one input arguments and may return more than one output arguments.### How do you call a function?

**How do I**

**call a function**?- Write the name of the
**function**. - Add parentheses () after the
**function’s**name. - Inside the parenthesis, add any parameters that the
**function**requires, separated by commas. - End the line with a semicolon ; .

### What are Matlab scripts?

The simplest type of

**MATLAB**^{®}program is called a**script**. A**script**is a file that contains multiple sequential lines of**MATLAB**commands and function calls. You can run a**script**by typing its name at the command line.### How do I create a script file?

**Let us understand the steps in creating a Shell**

**Script**:**Create a file**using a vi editor(or any other editor). Name**script file**with extension . sh.- Start the
**script**with #! /bin/sh. - Write some code.
- Save the
**script file**as filename.sh. - For executing the
**script**type bash filename.sh.

### What is the difference between a script file and a function Matlab?

**Scripts**versus

**Functions**

**Scripts** are m-**files** containing **MATLAB** statements. **MATLAB** “**functions**” are another type of m-**file**. The biggest **difference between scripts** and **functions** is that **functions** have input and output parameters. **Script files** can only operate on the variables that are hard-coded into their m-**file**.

### Can you put a function in a script Matlab?

Starting in R2016b,

**MATLAB**^{®}**scripts**, including live**scripts**,**can**contain code to define**functions**. These**functions**are called local**functions**. Local**functions**are useful**if you**want to reuse code within a**script**. By adding local**functions**,**you can**avoid creating and managing separate**function**files.