Setting up a matrix from input file?

1 Ansicht (letzte 30 Tage)
PSU
PSU am 5 Okt. 2014
Kommentiert: PSU am 5 Okt. 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!

Akzeptierte Antwort

Image Analyst
Image Analyst am 5 Okt. 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, ' ');

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 5 Okt. 2014

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by