MATLAB: Create Incidence matrix from Graph theory

circuitelectricalgraphincidencematrixnodes

How do I create the Incidence Matrix from the given graph?
I tried the following code, but the incidence matrix formed is completly wrong:
G=digraph( [ 1 2 2 2 3 4] , [4 1 3 4 1 3]);
I=incidence(G);
The nodes are 1, 2 ,3 and 4.

Best Answer

ok
>> G=digraph( [ 1 2 2 2 3 4] , [4 1 3 4 1 3]);
>> I = full(incidence(G))
I =
-1 1 0 0 1 0
0 -1 -1 -1 0 0
0 0 1 0 -1 1
1 0 0 1 0 -1