How to name rows in array ?

2 ビュー (過去 30 日間)
Alejandro
Alejandro 2014 年 11 月 4 日
コメント済み: Alejandro 2014 年 11 月 4 日
I have the following matrices:
reactions =
0 30.0000
40.0000 -30.0000
namb =
'node 3'
'node 5'
I need an instruction to make following:
node 3 0 30.0000
node 5 40.0000 -30.0000
I'am trying to use sprintf but can't seem to get it to work. Heres what I get:
node 0 30.00000
5 40.00000 -30.00000
here some of the code :
% ss is equal to number of names in this example; node 1, node 2, node 3,....node n
for i=1:ss
label = 'Reaction Matrix';
vheader = sprintf(namb{i})
hheader = 'Force_x Force_y';
printmat(reactions, label, vheader, hheader)
end
If anybody could head me in the right direction, I would appreciate it.

採用された回答

Image Analyst
Image Analyst 2014 年 11 月 4 日
Try this:
reactions =[...
0 30.0000
40.0000 -30.0000]
namb ={...
'node 3'
'node 5'}
% To be most general, find out how many rows and columns are in reactions.
[rows, columns] = size(reactions);
fprintf('Reaction Matrix Force_x Force_y\n');
for row = 1 : rows
fprintf('%s ', namb{row});
for col = 1 : columns
fprintf('%8.4f ', reactions(row, col));
end
fprintf('\n');
end
Printed in command window is:
Reaction Matrix Force_x Force_y
node 3 0.0000 30.0000
node 5 40.0000 -30.0000
  1 件のコメント
Alejandro
Alejandro 2014 年 11 月 4 日
Perfect!! Thank you very much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by