[英]Checking values of two vectors against eachother and then using the column location of equal entries to extract colums from a matrix in matlab
I'm doing a curve fitting problem in Matlab and so far I've set up some orthonormal polynomials along a specified range of x-values with x = (0:0.0001:40);
我正在Matlab中做曲线拟合问题,到目前为止,我已经沿着
x = (0:0.0001:40);
的x值的指定范围建立了一些正交多项式x = (0:0.0001:40);
The polynomials themselves are each a manipulation of that x vector and are stored as a row in a matrix. 多项式本身都是该x向量的一种运算,并作为行存储在矩阵中。 I also have some have data entries in the form of two vectors - one for the data x-coords and one for the actual values.
我也有一些具有两个向量形式的数据输入-一个用于数据x坐标,一个用于实际值。 I need a way to use the x-coords of my data points to find the same values in my continuous x-vector and then take the corresponding columns from my polynomial matrix and add them to a new matrix.
我需要一种使用数据点的x坐标在连续x矢量中找到相同值,然后从多项式矩阵中提取相应列并将其添加到新矩阵中的方法。
EDIT: To be more clear. 编辑:更清楚。 I have, for example:
我有例如:
x = [0 1 2 3 4 5]
Polynomial =
1 1 1 1 1 1
0 1 2 3 4 5
0 1 4 9 16 25
% Data values:
x-coord = [1 3 4]
values = [5 3 8]
I want to check the x-coord values against 'x' to find the corresponding columns and then pull out those columns from the polynomial matrix to get: 我想针对“ x”检查x坐标值以找到相应的列,然后从多项式矩阵中拉出这些列以获得:
Polynomial =
1 1 1
1 3 4
1 9 16
If your x
, Polynomial
, and xcoord
are the same length you could use logical indexing which is elegant; 如果
x
, Polynomial
和xcoord
的长度相同,则可以使用优雅的逻辑索引。 something along the lines of Polynomial(x==xcoord)
. 类似于
Polynomial(x==xcoord)
。 But since this doesn't seem to be the case, there's a less fancy solution with a for-loop and find(xcoord(i)==x)
但由于似乎并非如此,因此有一个花哨的解决方案,带有for循环和
find(xcoord(i)==x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.