How to name rows in array ?

2 Ansichten (letzte 30 Tage)
Alejandro
Alejandro am 4 Nov. 2014
Kommentiert: Alejandro am 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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 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
  1 Kommentar
Alejandro
Alejandro am 4 Nov. 2014
Perfect!! Thank you very much.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by