Setting up a matrix from input file?

1 次查看(过去 30 天)
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!

采纳的回答

Image Analyst
Image Analyst 2014-10-5
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, ' ');

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2014-10-5

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by