I need help using the "extract" function in Matlab

Hi everyone,
I am currently building a code, which is modified from another freeshare code available online. However, I am unclear how the "extract" function in Matlab works. I have looked through the help menu and searched using Google as well. However, I haven't been able to get much help.
Currently, the extract function used in the code looks like this:
[F0,Lf0]=extract(x,nf);
I keep getting the error: ??? Undefined function or method 'extract' for input arguments of type 'double'. whenever I try to run the entire code.
The help menu offers me an explanation on the extract function. However, the extract function in the help menu appears to have an extra parameter added. (i.e. [outmatrix, freq] = extract (h,outtype,z0). It explains that: outtype can be one of these case-insensitive strings 'ABCD_parameters', 'S_parameters', 'Y_parameters', 'Z_parameters', 'H_parameters', 'G_parameters', or 'T_parameters'. z0 is the reference impedance for the S-parameters. The default is 50 ohms.
As such, I'm somewhat convinced the original code (which has been around for some time) is missing a parameter that doesn't allow it to run on newer Matlab versions. But, I am not entirely sure since I'm unsure what z0/reference impedance means in this function.
Would appreciate any help on this, or just any links to website that provides an explanation/example on how to use the "extract" function.
Thanks!

1 Comment

I am also using the same code and i have the same problem.. have u fixed it

Sign in to comment.

 Accepted Answer

See, that means that you do not have the extract() you think you have on your path. Enter
>>path
and then see if the folder where you saved your extract.m file is listed or not, it should be at the top if you added it.
If you don't find it, then let's assume that you put extract.m in
c:\myfunctions
Then enter
>>addpath 'c:\myfunctions'
or start pathtool
>>pathtool
and make sure that you add the folder AND make sure that extract.m is ahead (above)
C:\Program Files\MATLAB\R2010b\toolbox\rf\rf\@rfckt\extract.m % rfckt method
When you enter
>>which extract
and see the path to the extract.m you want to use and NOT the rf version. Then you are ready to use it.

2 Comments

Many thanks! That solves the problem. But, I'm running into another problem.
It comes up with another error that says:
??? Undefined function or method 'cols' for input arguments of type 'double'.
Error in ==> irfbootfac2step at 55
Fb0 = companion(b0(2:end,:)',lags,cols(e0));
Error in ==> favarpcbootni at 50
[FYresp,Xresp]=irfbootfac2step(Y,lags,X,xindex,slowindex,K,shock,nsteps-1,nrep1,nrep2); % nsteps x equations x error bands
Cols appeared in:
Fb0 = companion(b0(2:end,:)',lags,cols(e0));
I tried using the same method to trouble shoot. But, it seems like cols isn't a function within Matlab? But, I've seen many codes using cols. So, I'm getting a little confused, because this don't seem to be a file that I've.
Apologies that I'm asking that many questions. This code seems much harder and longer to decipher than I initially thought.
Hello did you find a solution to this, it just happens that I ran into the same problem.

Sign in to comment.

More Answers (2)

It looks like from the error you are reporting that MATLAB is not able to find the function.
Did you add the folder that the function lives in to the MATLAB search path?
If you enter:
which extract
What is returned?
Use addpath() or pathtool and make sure you add all the folders you need to run the code you have downloaded.

1 Comment

Hi,
Thanks for answering. I do have all my codes in the same folder. So, that isn't the problem. The 'extract' function is actually in Matlab as I was able to get some help from the help menu. From what it seems, my extract function seems to be missing a parameter according to the help menu. Unfortunately, I do not know this "extract" function well enough to be able to spot the mistake. Hence, I would appreciate if anyone could help me with it, or refer me to somewhere with examples of 'extract' being used. It seems to be missing the z0 parameter, but I've no idea what it means by a reference impedence, according to the help menu.
Many thanks!

Sign in to comment.

I'm confused because your tags imply that your use case is an econometrics application, but the extract() help you cite is from a method in the RF Toolbox.
That extract() method expects that the input,h, is a rfckt, rfdata.data or rfdata.network object.
Is this really your application?

5 Comments

Hello,
Many thanks. I'm actually using the extract method to implement principal components analysis. So, I'll need to extract principal components from my data. The extract method is part of the code.
I'm trying to learn from this code I got from a paper, of which the authors have provided the code, before modifying it.
However, I am just stuck with the extract function. Would appreciate any help! Many thanks.
JZ, the extract() method that you are citing the help for is NOT the extract method you think it is. Please tell us what
>>which extract
returns. Copy and paste the answer from the MATLAB command window. The help you are asking about is for a RF application.
Hello,
This is the code with the function I'm looking at now, as the main code refused to run and told me the error lies with the extract() portion: [F0,Lf0]=extract(x,nf).
So, whenever I try to run my main code, it tells me the following:
??? Undefined function or method 'extract' for input arguments of type 'double'.
Error in ==> irfbootfac2step at 24
[F0,Lf0]=extract(x,nf);
Error in ==> favarpcbootni at 50
[FYresp,Xresp]=irfbootfac2step(Y,lags,X,xindex,slowindex,K,shock,nsteps-1,nrep1,nrep2); % nsteps x equations x error bands
Naturally, I tried to get help on the "extract" word within Matlab, and what I got was the function from the RF application.
Apologies if this seems really basic. I'm still learning the art of coding, mainly thru' looking at codes/papers available out there and learning them line by line to understand what exactly they are doing. Many thanks!
The following partial code is from irfbootfac2step.m , the code that has the above described problems.
% Bootstrap confidence interval on IRF's, Based on Kilian (1998)
% Jean Boivin
% 11/08/01
% modified 9/14/02 to resample factors
% y = T x K matrix of dependent variables
% x = T x N1 (N1 <= N) matrix of series of interest
% k = number of factors
% shock = K x 1 vector of initial impulse
% nir = number of periods in the IRF
% nrep1 = number of bootstrap replications -- factors
% nrep2 -- parameters
% xindex specifies elements of x we want impulse responses
function [imp,impx]=irfbootfac2step(y,lags,x,xindex,slowindex,nf,shock,nir,nrep1,nrep2)
[T,N]=size(x);
M=size(y,2);
% x's for impulse responses
xir=x(:,xindex);
% first step - extract PC from X
[F0,Lf0]=extract(x,nf);
u0=x-F0*Lf0';
xslow=x(:,slowindex);
[Fslow0,Lfslow0]=extract(xslow,nf);
Fr0 = facrot(F0,y(:,end),Fslow0);
fy0=[Fr0,y];
bx0 = olssvd(xir,fy0);
Why are you not answering the question I asked you?
"Please tell us what
>>which extract
returns. Copy and paste the answer from the MATLAB command window."
Oops sorry! Totally misunderstood your question.
It returned the following:
C:\Program Files\MATLAB\R2010b\toolbox\rf\rf\@rfckt\extract.m % rfckt method

Sign in to comment.

Asked:

jj
on 7 Oct 2011

Commented:

on 15 Jul 2017

Community Treasure Hunt

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

Start Hunting!