Setting up a matrix from input file?

1 回表示 (過去 30 日間)
PSU
PSU 2014 年 10 月 5 日
コメント済み: PSU 2014 年 10 月 5 日
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 件のコメント
PSU
PSU 2014 年 10 月 5 日
Thank you so much!!
It worked!

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 10 月 5 日
  1 件のコメント
PSU
PSU 2014 年 10 月 5 日
Thank you so much!
It worked!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by