필터 지우기
필터 지우기

Format Questions

조회 수: 1 (최근 30일)
Xiao Tang
Xiao Tang 2012년 6월 24일
MATLAB has strict format requirement.
1. A and B are in double format. C is in cell format. (C is read by: [~,C,~] = xlsread('C:\XXX\XXX.xlsx','Sheet1','M2:X2')
A =
[10
15
20
25
30];
B = [1423992 1356920 1356920
440353 436518 436518
1325369 1307792 1307792
1485221 1165422 1162373
1496009 1489431 1489431
6170946 5756085 5753036
];
C ='SECTOR' 'MKVALM' 'DVYDC' 'DVYLD500'
How can I combine A, B and C to get a matrix D so that:
D =
SECTOR MKVALM DVYDC DVYLD500
10 1423992 1356920 1356920
15 440353 436518 436518
20 1325369 1307792 1307792
25 1485221 1165422 1162373
30 1496009 1489431 1489431
SUM 6170946 5756085 5753036
Notice that the D(7,1) = 'SUM'.
2. Once I get D, I want to add an empty row and a row with numbers to get E,
E = SECTOR MKVALM DVYDC DVYLD500
10 1423992 1356920 1356920
15 440353 436518 436518
20 1325369 1307792 1307792
25 1485221 1165422 1162373
30 1496009 1489431 1489431
SUM 6170946 5756085 5753036
35 12 12 14
Notice there is an empty row between 'SUM 6170946 5756085 5753036' and '35 12 12 14'.
Any help will be appreciated!
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 6월 24일
You cannot construct that D vector except as a character array, in which case D(7,1) would be 'S' .
If you construct D as a cell array, you would have to show quotation marks and [] in the display of it:
'SECTOR' 'MKVALM' 'DVYDC' DVYLD500'
[10] [1423992] [1356920] [1356920]
and so on.
Xiao Tang
Xiao Tang 2012년 6월 25일
You are absolutely right. In this situation I guess I have to use cell array.

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 6월 24일
Ac = num2cell(A);
Bc = num2cell(B);
D = [C;Ac,Bc(1:end-1,:);{'SUM'},Bc(end,:)];
E = [D;cell(1,4);{35, 12, 12, 14}];
  댓글 수: 1
Xiao Tang
Xiao Tang 2012년 6월 25일
: )

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by