hi guys
i need a code to construct this matrix, the code should allow the user to insert h1,h2...h(n-1)

 Akzeptierte Antwort

Guillaume
Guillaume am 23 Nov. 2014

2 Stimmen

How about:
m = circshift(eye(numel(h) + 1), 1, 2)
m(end, 2:end) = h;

2 Kommentare

janny
janny am 25 Nov. 2014
this one gave an error
??? Error using ==> circshift Too many input arguments.
You must be using an older version of matlab then.
m = circshift(eye(numel(h) + 1), [0 1])
should work regardless of version

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Star Strider
Star Strider am 20 Nov. 2014

1 Stimme

Janny, meet compan. It generates the companion-form matrix you want.

4 Kommentare

janny
janny am 23 Nov. 2014
sorry for being late.... i try it but it didn't work...
Star Strider
Star Strider am 23 Nov. 2014
Bearbeitet: Star Strider am 23 Nov. 2014
This isn’t actually a companion form matrix, but it has the form you want:
h = randi(10,1,4); % Create ‘h’ Vector
D = diag(ones(1,length(h)),1);
D(end,:) = [1 h];
janny
janny am 25 Nov. 2014
the last line came in decimal.... it should be in binary,, it came as:
0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 8 10 7 1
how to make it in binary
I have no idea what you’re doing. To make it binary with the randi function, change that line to:
len = 4; % Length of number string
h = randi([0 1],1,len);
To produce a binary string from a decimal number, use the dec2bin function.

Melden Sie sich an, um zu kommentieren.

Kategorien

Tags

Gefragt:

am 20 Nov. 2014

Kommentiert:

am 25 Nov. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by