Generate row vectors that match indexes

조회 수: 2 (최근 30일)
Happy Bear
Happy Bear 2020년 2월 6일
댓글: Happy Bear 2020년 2월 6일
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];
Happy Bear
Happy Bear 2020년 2월 6일
Exactly what I mean!

댓글을 달려면 로그인하십시오.

채택된 답변

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);
  댓글 수: 1
Happy Bear
Happy Bear 2020년 2월 6일
Thank you so much, exactly what I needed!

댓글을 달려면 로그인하십시오.

추가 답변 (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