Creating specific vertical matrix

조회 수: 15 (최근 30일)
Jakub F
Jakub F 2016년 8월 25일
답변: Andrei Bobrov 2016년 8월 25일
Hello I want to create vertical matrix with one column. The idea is that:
-i need to define how many rows i want (time),
-the matrix will be a rectangle signal that i use in simulink
-the signal goes for example: 20 rows of 0, 50 rows of some value, 10 rows of 0 and so on.
I managed to do this like that
t= [1:tmax]';
x1= zeros(99,1);
x2= -0.0015* ones(600,1);
x3= zeros(tmax-99-600,1);
x=vertcat(x1,x2,x3);
But I am sure that the easier way exist, especcially that later I want to use variables to create this matrix and the signal can have unspecified number of states.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 8월 25일
t = [100,600];
x = zeros(tmax,1);
x(t(1):(sum(t)-1)) = -.0015;

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by