How to name rows in array ?

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by