adding a padding to matrix.

2 次查看(过去 30 天)
Portgas Ace
Portgas Ace 2012-9-30
for example, i have a vector A = [ which has 43 elements ]
if i use reshape (A,9,5)
there is an error since i lack 2 elements to make a 5x9 table. how do i add empty elements to the matrix?
  1 个评论
Portgas Ace
Portgas Ace 2012-9-30
so there is a value of a matrix which will only be a space.

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2012-9-30
编辑:Matt J 2012-9-30
You haven't specified where the padding should go (beginning/end) and with what values, but this should give you the idea:
A(45)=0; %pad the vector with zeros
B=reshape (A,9,5)
  2 个评论
Portgas Ace
Portgas Ace 2012-9-30
could i possibly do
A(45)= ' ' %pad with only a blank
also, is there any other way to put the paddings on random places.
Matt J
Matt J 2012-9-30
With cell arrays, you can do something like that,
A=num2cell(A);
A{45}=[]; %pad with empty
B=reshape(A,9,5);
As for "padding in random places", you can do things like this:
A=num2cell(A);
B=cell(9,5);
B(1:20)=A(1:20);
B(23:end)=A(21:end);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by