Generate row vectors that match indexes

2 次查看(过去 30 天)
I have a 1x3 vector with the following values: 0.03 0.06 0.11 and another 1x3 vector with the following values: 0.5667 0.7667 0.8667.
Is it possible to generate a row vector of 100 spaced points between 0.03 and 0.01 and another one between 0.5667 and 0.8667? But with the index of 0.06 in the first row vector being the same index of 0.7667 in the second row vector.
  2 个评论
Rik
Rik 2020-2-6
Sure, especially if you don't insist on a uniform spacing, otherwise this is impossibe. You mean like the example below, but with a total length of 100 elements for each vector?
v1=[0.03 0.045 0.06 0.07 0.11 ];
v2=[0.5667 0.6 0.7667 0.8 0.8667];

请先登录,再进行评论。

采纳的回答

Rik
Rik 2020-2-6
The code below will sample points over a parabola, since three points fully determine a second order polynomial. The middle point is guaranteed to match up, but there is no guarantee that the points will be increasing.
v1=[0.03 0.06 0.11];
v2=[0.5667 0.7667 0.8667];
N=6;%set number of elements the output vectors should have
x_short=[0 0.5 1];
x_long=linspace(0,1,N);
if mod(N,2)==0
%With an odd N 0.5 will be in the x vector, but with an even N it will
%not, so change one of the values to 0.5.
x_long(N/2)=0.5;
end
p1=polyfit(x_short,v1,2);
v1_long=polyval(p1,x_long);
p2=polyfit(x_short,v2,2);
v2_long=polyval(p2,x_long);

更多回答(0 个)

类别

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