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 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