Interp3 variables with monotonic increasing values

조회 수: 2 (최근 30일)
Ryan
Ryan 2016년 7월 27일
편집: John BG 2016년 7월 29일
Hello, I'm trying to interpolate 3 variables in a matrix. I'm trying to use interp3(), but the trouble is the columns aren't monotonic increasing. Heres a sample matrix:
alt, mach, alpha, Cn
0 0.1 -2 0.55
0 0.1 0 0.5
0 0.1 2 0.55
0 1 -2 1.1
0 1 0 1
0 1 2 1.1
1000 0.1 -2 0.8
1000 0.1 0 0.75
1000 0.1 2 0.8
1000 1 -2 1.35
1000 1 0 1.25
1000 1 2 1.35
Say that matrix is A
interp3(A(:,1),A(:,2),A(:,3),A, 500, 0.1, 0)
I want a value of Cn for a given alt, mach, and alpha. Is this possible or do I need to split up matrix to make it more manageable?
Thanks!

채택된 답변

John BG
John BG 2016년 7월 28일
Let me split your data first, to avoid mixing different variables
A=[0 0.1 -2 0.55
0 0.1 0 0.5
0 0.1 2 0.55
0 1 -2 1.1
0 1 0 1
0 1 2 1.1
1000 0.1 -2 0.8
1000 0.1 0 0.75
1000 0.1 2 0.8
1000 1 -2 1.35
1000 1 0 1.25
1000 1 2 1.35]
A=A'
alt=A(1,:);match=A(2,:);alpha=A(3,:);Cn=A(4,:)
Now, when interpolating, it shouldn't be relevant whether your data is 'monotonic' or not. It's the speed of change what matters.
For your alpha signal:
n_alpha1=[1:1:length(alpha)] % time base original signal
r=3;
alpha2=interp(alpha,3) % interpolating, r=3
n_alpha2=[1:1:length(alpha2)] % time base interpolated signal
the following doesn't work because original and interpolated do not have same time base
plot(n_alpha1,alpha,'red',n_alpha2,alpha2,'b','LineWidth',1.5);
to get them same time base:
n_alpha13=[1:r:r*length(alpha)];
f3=figure(3);plot(n_alpha13,alpha,'r',n_alpha2,alpha2,'b','LineWidth',1.5);grid on;
f3.Name='signal alpha';
xlabel('t');ylabel('alpha');
So, as long as you keep same interpolation rate for all your signals, in this example r=3, all your signals will remain aligned, which is you have specifically mentioned in the question.
Repeating for the other 3 signals:
n_alt=[1:1:length(alt)];
alt2=interp(alt,r);
n_alt13=[1:r:r*length(alt)];
n_alt2=[1:1:length(alt2)];
n_Cn=[1:1:length(Cn)];
Cn2=interp(Cn,r);
n_Cn13=[1:r:r*length(Cn)];
n_Cn2=[1:1:length(Cn2)];
n_match=[1:1:length(match)];
match2=interp(match,r);
n_match13=[1:r:r*length(match)];
n_match2=[1:1:length(match2)];
f1=figure(1);plot(n_alt13,alt,'red',n_alt2,alt2,'blue','LineWidth',1.5);grid on;
f1.Name='signal alt';
f2=figure(2);plot(n_match13,match,'red',n_match2,match2,'blue','LineWidth',1.5);grid on;
f2.Name='signal match';
f4=figure(4);plot(n_Cn13,Cn,'red',n_Cn2,Cn2,'blue','LineWidth',1.5);grid on;
f4.Name='signal Cn';
You can repack the signals back to the original format
B=[alt2;match2;alpha2;Cn2];
B=B'
=
1.0e+03 *
0 0.0001 -0.0020 0.0005
0 0.0001 -0.0015 0.0005
0 0.0001 -0.0009 0.0005
0 0.0001 0.0000 0.0005
0 0.0000 0.0012 0.0005
0 0.0000 0.0020 0.0005
-0.0000 0.0001 0.0020 0.0005
-0.0057 0.0004 0.0008 0.0007
-0.0062 0.0007 -0.0008 0.0009
0.0000 0.0010 -0.0020 0.0011
0.0266 0.0011 -0.0021 0.0011
0.0305 0.0010 -0.0014 0.0011
-0.0000 0.0010 0 0.0010
-0.0853 0.0010 0.0014 0.0010
-0.1089 0.0011 0.0021 0.0011
-0.0000 0.0010 0.0020 0.0011
..
there are other commands you may want to have a look, to control the ringing. Linear interpolation can be done with command linspace, but linspace does not take vector inputs, just scalars.
Ryan would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John
  댓글 수: 2
Ryan
Ryan 2016년 7월 28일
Hi John,
Thanks for the work. The original point I'm trying to get at is can I use interp3() to find a value (Cn) for my three variables (alt, mach, alpha) without splitting up the matrix? What you explained, and correct me if I'm wrong, was a way to get more data between the discontinuities of each column of data. That's fine work, but I'm really wanting that one value if I plug in three variable values.
Say alt = 500 mach = 0.1 alpha = 0
I'm only interpolating between the alt values 0 and 1000 so looking for a Cn value between 0.5 and 0.75 (using matrix 'A').
That's only one variable. I was thinking I could use interp3 to solve for 3 interpolations.
Please let me know if I totally misinterpreted your work.
John BG
John BG 2016년 7월 29일
편집: John BG 2016년 7월 29일
you say you want to to interpolate Cn, one of the signals in the, let me call it this way, the bus with 4 signals in your question.
Yet, you also say you want all the other signals aligned so that you can pick one value of Cn, and it should be aligned to those in other signals of the bus, for the same time reference.
So, you really have to interpolate something within the samples of the rest of signals of the bus, even if you think you don't, otherwise different time references mess up the bus.
My guess is that this parallel interpolation you want is one of the reasons why Mathworks issued a compatibility consideration and recommends an alternative
expand the R2013 menu 'Mathematics' otherwise when searching 'interp3' nothing apparently found.
Before knowing about such recommendation, I already showed the basics of you how to 'unpack' the bus, interpolate with same time reference, and 'repack'.
Please feel free to carry on your endeavour along the line you consider suitable. If you think that interp3 is the function you have to use, perhaps other forum users may supply a closed solution.
I would like to close my answer, so if you don't really want to mark my answer as Accepted Answer, or even click on the the thumbs-up, it's going to be ok.
Regards
John BG

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by