Setting up a matrix from input file?

1 visualizzazione (ultimi 30 giorni)
PSU
PSU il 5 Ott 2014
Commentato: PSU il 5 Ott 2014
I have a file that has 7 nodes and 8 elements that I am retrieving data from.
I am currently trying to set-up a stiffness matrix but I am struggling with coming up with the correct code to build my matrix.
Below is the format from my .inp file. The first row is the number of the element and the other two columns are were the nodes are connected at. So in other words element 1 is connected at nodes 1 and 7.
if true
% code
end
1 1 7
2 3 5
3 7 6
4 4 6
5 4 1
6 4 2
7 5 7
8 2 5
I got it to read each column by calling each column N1, N2, N3 but then when I do A=[N1; N2; N3]
it gives me:
if true
% code
end
A =
1
2
3
4
5
6
7
8
1
3
7
4
4
4
5
2
7
5
6
6
1
2
7
5
Please Help
Thank you!

Risposta accettata

Image Analyst
Image Analyst il 5 Ott 2014
Using a semicolon puts the matrices one atop the other (vertical concatenation). Using a comma puts them side by side (horizontal concatenation). Try this
A=[N1, N2, N3]
Or just read it into A directly with dlmread() or readtable().
A = dlmread(filename, ' ');

Più risposte (1)

Azzi Abdelmalek
Azzi Abdelmalek il 5 Ott 2014
A=[N1 N2 N3]

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by