How to name rows in array ?

3 views (last 30 days)
Alejandro
Alejandro on 4 Nov 2014
Commented: Alejandro on 4 Nov 2014
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.

Accepted Answer

Image Analyst
Image Analyst on 4 Nov 2014
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

More Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!