Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Trying to understand vectors division in Matlab

Status
Not open for further replies.

EngIntoHW

Member
I studied the following for forming a pulse train in Matlab:

f=10; %frequency of the impulse in Hz
fs=f*10; % sample frequency is 10 times higher
t=0:1/fs:1; % time vector
y=zeros(size(t));
y(1:fs/f:end)=1;
plot(t,y);

I'm trying to understand the following 2 operations:
1.
t=0:1/fs:1; % time vector

What does it do?

2.
y(1:fs/f:end)=1;

What is the result of 1:fs/f:end ?


Thanks in advance!
 
the first operation generates the time matrix starting from the value 0 and the step size is 1/fs. the final value is 1.
In your second point 1:1/fs:end represents the index of array. it starts from 1 till the last value, with a step size of fs/f. it means that by starting from the value of 1, it replace every value in the y matrix to 1 [ y(1:fs/f:end) ], at a step size of fs/f
 
here in matlab the time t is variable whose values are ranging from 0 to 1 with a step size of 1/fs, hence all its values are stored in a matrix of one row and 101 columns known as row matrix or row vector. it does not mean that we are considering the time as a vector quantity. the time here is only a variable in matlab. in matlab we normally deal with matrices.
 
I don't know anything about Matlab, but how is time a vector? I would think it was scaler quantity.

He meant that t is a vector (or array) of time values.

t = 0:0.1:1;
the above creates an 11 element array (1x11 vector) with values from zero to 1 and 0.1 increment and stores it in the variable t.

In matlab evereything is (internally) treated as a matrix structure. Even a simple scalar is represented as 1x1 matrix.
 
Last edited:
EngIntoHW & misterT,

Well, the elements of a vector can be inserted into a array or matrix, but Matlab should not call the row or column of an array or matrix a "vector". It causes confusion.

Ratch
 
Last edited:
EngIntoHW & misterT,

Well, the elements of a vector can be inserted into a array or matrix, but Matlab should not call the row or column of an array or matrix a "vector". It causes confusion.

Ratch

Well, it doesn't. It calls all of them matrices. People call a column (or row) matrices vectors and 1x1 matrices scalar.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top