I am trying to calculate currents from a circuit. I wrote a text file and I am trying to enter a 9x9 matrices and a 9x1 vector from the text file. I was able to get the 9x9 matrices to work properly, however I am having trouble reading the 9 x 1 matrices. I keep getting the error:
Subscripted assignment dimension mismatch.
Error in Project (line 29)
[RHS_vector(jj,:),count]=fscanf(fileid,'%d',matrix_size2)
The code for the 9x9 matrices that works is shown below:
%Script to read the circuit system
fileid = fopen('my_circuit.txt','rt');
title=fgetl(fileid)
title = fgetl(fileid)
[matrix_size,count] = fscanf(fileid,'%d',1)
nothing = fgetl(fileid) %advances to the next line
title = fgetl(fileid);
%initialize A_matrix
A_matrix = zeros(matrix_size, matrix_size)
%Read system A matrix
for ii = 1:matrix_size
[A_matrix(ii,:),count]=fscanf(fileid,'%d',matrix_size)
nothing=fgetl(fileid)
end
The code I am having trouble with is shown below which starts at the :
%start back here
title = fgetl(fileid)
[matrix_size2,count]=fscanf(fileid,'%d',1)
%nothing = fgetl(fileid)
%initialize B_Matrix
RHS_vector = zeros(matrix_size2,matrix_size2)
%Read System B matrix
for jj = 1:matrix_size2
[RHS_vector(jj,:),count]=fscanf(fileid,'%d',matrix_size2)
%nothing=fgetl(fileid)
end
Can someone give me some direction in my mistake?
This is the text file I am using:
My circuit project data
Size of the problem
9
System Matrix
1 0 1 1 0 0 0 0 0
0 1 1 0 0 1 0 0 0
1 1 0 0 0 0 1 0 0
0 0 0 0 1 1 0 1 0
0 0 0 0 0 0 1 1 1
18 14 10 0 0 0 0 0 0
0 0 10 15 12 6 0 0 0
0 14 0 0 0 6 0 11 0
0 0 0 0 12 0 0 11 16
Right hand side
9
0
0
0
0
0
24
0
87
76
