convert a vector to 2D matrix
显示 更早的评论
Hi all
How do I convert a vector into a two-dimensional matrix like this?
A=[1 2 3 4 5 6 7]
A=[ 1 2 3
4 5 6
7 0 0]
采纳的回答
更多回答(1 个)
Walter Roberson
2021-7-18
buffer(A, 3).'
This requires the Communications System Toolbox
4 个评论
reta jon
2021-7-18
Walter Roberson
2021-7-18
No. MATLAB has no possibility of having "holes" in a numeric array.
reta jon
2021-7-18
Walter Roberson
2021-7-19
Questions for you:
If, hypothetically, MATLAB did permit "holes" in arrays, then how should that work?
In the below, if we let a "hole" be represented by H, then what should be the result of:
[1 H] + [H 2]
[1 H] .* [H 2]
exp(H)
mean([2 4 H]) %is that (2+4)/2 or is that (2+4)/3 ?
inv([2 0; 0 H])
inv([2 0 H; 0 2 H; H H H]) %should that be [1/2 0 H; 0 1/2 H; H H H] -- inverse of the part that is not holes?
Should
sum([2 3 4]) == sum([7 H H]) %or should there be a way to distinguish the two?
Should a hole be treated the same as NaN for mathematical purposes? Should there be any difference between NaN and holes, other than that holes display empty? If you have
[1 H 2]
then how should that display? Should you count on people knowing what the current "format" is, and how many spaces would normally be present? "format long" normally has more blanks between entries than "format short" does, so if you put spaces in instead of holes, then will users be able to reliably figure out that
1 2
is
[1 H H 2]
displayed in format long, and not
[1 H H H 2]
displayed in format short?
Your sample output tends to suggest that you want the right-hand-side display of entries to "collapse" around all holes. But if so then how is the user intended to tell the difference between
1 2 H
3 4 H
and
1 2
3 4
??
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!