[英]2-column matrix from 2 vectors in MATLAB
This feels like it should be simple. 感觉应该很简单。
I am building a minimum distance classifier and I want to put feature1 and feature2 into the same matrix so that I can call them and get answers like this. 我正在建立一个最小距离分类器,我想将feature1和feature2放在同一矩阵中,这样我就可以调用它们并得到这样的答案。
featureVector(1,:) =
all the feature1
values featureVector(1,:) =
所有feature1
值
featureVector(2,:) =
all the feature2
values featureVector(2,:) =
所有feature2
值
I'm looping through and hoping to put these values into the featureVector
as the loop runs. 我正在遍历,希望在循环运行时将这些值放入featureVector
中。
I'm fairy new to MATLAB so i'm not sure how to put that into words. 我对MATLAB还是陌生的,所以我不确定如何将其表达出来。 Hopefully that makes enough sense. 希望这有足够的道理。
Thanks everyone. 感谢大家。
If your feature1
is a horizontal vector, then do: 如果feature1
是水平向量,请执行以下操作:
featureVector = [ feature1 ; feature2 ]
Else (if vertical), do: 否则(如果是垂直的话),请执行以下操作:
featureVector = [ feature1 , feature2 ]
If you don't know it's orientation, you can always do a reshape
: 如果你不知道它的方向做,你总是可以做一个reshape
:
feature1 = reshape(feature1, 1, numel(feature1))
... what will make feature1
horizontal, or: ...将使feature1
水平的原因,或:
feature1 = reshape(feature1, numel(feature1), 1)
... what will make feature1
vertical. ...是什么使feature1
垂直。
reshape
used like that will make horizontal/vertical vector from any vector/matrix, taking particular values one-by-one from the original source. 像这样使用reshape
可以从任何矢量/矩阵生成水平/垂直矢量,并与原始源一一对应地取特定值。
Edit : A proof that it works: 编辑 :一个有效的证明:
>> a = [1 ; 2 ; 3 ; 4 ; 5];
>> b = [6 ; 7 ; 8 ; 9 ; 10];
>> ab = [a, b]
ab =
1 6
2 7
3 8
4 9
5 10
>> ab(2,:)
ans =
2 7
Edit : If your feature1
and feature2
are scalars, and you want to add them to the featureVector
one-by-one in every iteration, then do: 编辑 :如果您的feature1
和feature2
是标量,并且您想在每次迭代中将它们一个一地添加到featureVector
,请执行以下操作:
featureVector = []
for i = 1:...
feature1 = ...;
feature2 = ...;
featureVector = [featureVector; [feature1, feature2]];
end
您是否考虑过使用它?
results = [values1,values2];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.