get same column of matrix automatically.

조회 수: 2 (최근 30일)
heo jaemu
heo jaemu 2015년 1월 30일
편집: Guillaume 2015년 1월 30일
I want to get same column 'automatically'.
example,
A = [ 1 2 3 4 5] 1X5
B = [ 3 4 2 ] 1X3
I want to get 1X10 matrixs of A,B. (regardless of value)
outcome,
A = [ 1 2 3 4 5 0 0 0 0 0 ]
B = [ 3 4 2 0 0 0 0 0 0 0 ]

채택된 답변

Guillaume
Guillaume 2015년 1월 30일
편집: Guillaume 2015년 1월 30일
function resized = expandcolumns(m, c)
%m a 1d or 2d matrix with less than c columns
%c the number of columns to expand to. Additional columns are filled with 0.
%input checking
validateattributes(m, {'numeric', 'logical'}, {'2d'}, 1);
validateattributes(c, {'numeric'}, {'scalar', 'positive'}, 2);
if size(m, 2) > c
error('matrix is already wider than requested');
end
%the resizing:
resized = [m zeros(size(m, 1), c-size(m, 2))];
end

추가 답변 (1개)

Mischa Kim
Mischa Kim 2015년 1월 30일
Heo, how about simply
A = [A zeros(1,10-numel(A))]
for example.

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by