I have a question about matlab function 'interp2'
1 view (last 30 days)
Show older comments
Hi
I'm beginner matlab uer, so I need your help.
I made a program for my study.
Follow this is part of my program.
-------------------------------------------------------------------------------------------------------------------------------
function f=fct_trans(freq0,amp0)
toto1=load('TR_FCT.mat');
Phase=toto1.PHASE2;
Gain=toto1.GAIN2;
freq2=toto1.FREQ2;
freq2=freq2*2*pi;
amp2=0.1;
gain_ponct=interp2(freq2,amp2,Gain,[freq0],[amp0],'spline');
phase_ponct=interp2(freq2,amp2,Phase,[freq0],[amp0],'spline');
f=[gain_ponct phase_ponct];
-------------------------------------------------------------------------------------------------------------------------
An error occured like this
"??? Error using ==> interp2 at 147
X and Y must both be vectors or both be matrices."
What could i do??????
Please help me!!
0 Comments
Answers (1)
Walter Roberson
on 31 Jul 2015
You assigned amp2=0.1 and then used that as your only "Y" coordinate. Your third matrix, "Gain" in this case must be either the same size as your "Y" (amp2) or else the third matrix must be length(Y) by length(X) -- so your Gain would have to be length(amp2) by length(freq2) which would be 1 by length(freq2). And it isn't.
You should only use interp2() when you have a 2D array of values, not when you have a vector of values. If you have only a vector of values then you would use interp1()
gain_ponct = interp1(freq2, Gain, freq0, 'spline'); %if Gain is a vector
If Gain is a 2D array whose entries are 0.1 apart in the first dimension, then:
amp2 = 0.1 * (1:size(Gain,1));
gain_ponct = interp2(freq2,amp2,Gain,[freq0],[amp0],'spline');
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!