Lets say, we have the following two-dimensional array in Matlab:
可以说,我们在Matlab中有以下二维数组:
A=[0 451
0 446
0 543
.....]
etc. I want to create another, one-dimensional array, that will do this: For example, lets call the 1-D array B
, B(1)
will "show" to [0 451]
. B(2) will "show" to [0 446]
, B(3) will "show" to [0 543]
and so on.I hope that my desired result is pretty clear to anyone who could give me a bit help.
我想创建另一个一维数组,它将执行此操作:例如,让我们调用1-D数组B,B(1)将“显示”到[0 451]。 B(2)将“显示”到[0 446],B(3)将“显示”到[0 543],依此类推。我希望任何可以给我一点帮助的人都能清楚我想要的结果。
2 个解决方案
#1
1
Two ways:
两种方式:
a=1:10
split_a1=(reshape(a,2,[])).';
Access split_a1
as split_a1(1,:),...,split_a1(5,:);
.
将split_a1作为split_a1(1,:),...,split_a1(5,:) ;.
split_a2=mat2cell(a,1,2*ones(1,numel(a)/2));
Access split_a2
as split_a2{1},...,split_a2{5};
.
将split_a2作为split_a2 {1},...,split_a2 {5};进行访问。
#2
0
Well, what you have just set is impossible, you are mixing the arrays and the Dimensions. As you have explained it, B is 2-D, and A is 1-D. You can do what you want by doing this:
那么,你刚刚设置的是不可能的,你正在混合数组和Dimensions。正如您所解释的那样,B是2-D,A是1-D。这样做你可以做你想做的事:
j=0;
i=1;
while i<=size(A,2)/2;
j=j+1;
B(i,1)=A(j);
j=j+1;
B(i,2)=A(j);
i=i+1;
end
#1
1
Two ways:
两种方式:
a=1:10
split_a1=(reshape(a,2,[])).';
Access split_a1
as split_a1(1,:),...,split_a1(5,:);
.
将split_a1作为split_a1(1,:),...,split_a1(5,:) ;.
split_a2=mat2cell(a,1,2*ones(1,numel(a)/2));
Access split_a2
as split_a2{1},...,split_a2{5};
.
将split_a2作为split_a2 {1},...,split_a2 {5};进行访问。
#2
0
Well, what you have just set is impossible, you are mixing the arrays and the Dimensions. As you have explained it, B is 2-D, and A is 1-D. You can do what you want by doing this:
那么,你刚刚设置的是不可能的,你正在混合数组和Dimensions。正如您所解释的那样,B是2-D,A是1-D。这样做你可以做你想做的事:
j=0;
i=1;
while i<=size(A,2)/2;
j=j+1;
B(i,1)=A(j);
j=j+1;
B(i,2)=A(j);
i=i+1;
end