Filter löschen
Filter löschen

Generate row vectors that match indexes

1 Ansicht (letzte 30 Tage)
Happy Bear
Happy Bear am 6 Feb. 2020
Kommentiert: Happy Bear am 6 Feb. 2020
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 Kommentare
Rik
Rik am 6 Feb. 2020
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 am 6 Feb. 2020
Exactly what I mean!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rik
Rik am 6 Feb. 2020
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);

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by