I’m trying to do a script for nodal analysis for an arbitrary circuit(much like spice).I want to import data from a text file and create a matrice on which further operations will be based on.
so I’ve used textscan
fid = fopen('text2.txt');
netlist = textscan(fid,'%s%s%d%d%d%d%f');
so for an input file like this:
R1 R 1 0 3 0 0
C1 C 1 0 5 0 0
L1 L 2 1 10 0 0
R2 R 1 2 1 0 0
i1 Iac 2 0 1 1 0.523
the result wil be this
{5x1 cell} {5x1 cell} [5x1 int32] [5x1 int32] [5x1 int32] [5x1 int32]
[5x1 double]
the problem is, now I can’t call any individual value from the matrice. So I’m trying to figure out how to recreate the original matrice(if possible) and if that didn’t work, could you show me a way to call individual elements (like for example C in (2,2)?
Thanks in advance
Cell arrays are simply another way to store data. Specifically, cell arrays are needed when each cell contains data of different type or different dimensions (in which case, using a matrix won’t work).
To access an individual element in the cell array, you use curly braces (
{}). Aftertextscanyour data is stored as columns, so you first access the i-th column byC{i}.Then you need to think what your cell contains. Column 2 contains strings, so it’s another cell array (you can also verify it in the result — column 2 is described as a
{5x1 cell}). Therefore, you’ll need to use curly braces again. If you want to access the 2nd element in the 2nd column, you will have to write:P.S.
If you were to access the 2nd element in the 3rd column, you’d be using round braces
()for the second subscript, because the second column is a vector. In such case, the syntax should be: