How to use dct2() in matlab? - matlab

I am trying to pass a matrix to dct2 function but it is showing error. I am using matlab version R2012a. I have a matrix B which just used as argument like below
B = dct2(A);
disp(B);
Error is showing like this
Undefined function 'dct2' for input arguments of type 'uint8'.
Error in image_dct (line 24)
B = dct2(A);

You have to have the image processing toolkit in order to use that. Assuming you have that, then it should be just as simple as you listed.

Related

Face detection using matlab

tried this code
A=imread('1.jpg');
FaceDetector=vision.CascadeObjectDetector();
BBOX=step(FaceDetector,A);
B=insertObjectAnnotation(A,'rectangle',BBOX,'Face');
imshow(B),title('Detected Faces');
n=size(BBOX,1);
str_n=num2str(n);
str=strcat('number of detected faces are ',str_n);
disp(str);
this error show with me
Undefined function 'insertObjectAnnotation' for input arguments of type 'uint8'.
Error in Detected_faces (line 9)
B=insertObjectAnnotation(A,'rectangle',BBOX,'Face');
You just need to change the type of your image.
A type must be uint8 and the "insertObjectAnnotation" function only takes different inputs.
Please try:
A=imread('1.jpg');
FaceDetector=vision.CascadeObjectDetector();
BBOX=step(FaceDetector,A);
B=insertObjectAnnotation(rgb2gray(A),'rectangle',BBOX,'Face');
Actually, I tried this:
I = imread('coins.png');
FaceDetector=vision.CascadeObjectDetector();
BBOX=step(FaceDetector,I);
B=insertObjectAnnotation(I,'rectangle',BBOX,'Face');
And I is uint8, and it worked.
Using your dataset, it worked just fine. See Image output.

Why is fgoalattain built-in function not working in MATLAB?

I'm trying to invoke an fgoalattain function (computing a function minimum with a goal-attainment algorithm) in MATLAB. According to documentation, it should look like this:
[X,FVAL,ATTAINFACTOR] = FGOALATTAIN(#objf_1,x0,goal,weight)
where #objf_1 is a function handle for a function defined in objf_1 m-file and the rest are some arguments I set on my own. They are not important in any case, because evidently MATLAB has a problem with that function, as it throws:
>> rospar_4
Undefined function 'fgoalattain' for input arguments of type 'function_handle'.
Error in rospar_4 (line 29)
[X,FVAL,ATTAINFACTOR] = fgoalattain(#objf_1,x0,goal,weight)
However, I already know that the function works fine on another MATLAB version - R2011b (the one I'm using is R2012b), but with first argument as char instead:
[X,FVAL,ATTAINFACTOR] = fgoalattain('objf_1',x0,goal,weight)
If I try to invoke it like this in mine though, the error is almost the same:
>> rospar_4
Undefined function 'fgoalattain' for input arguments of type 'char'.
Error in rospar_4 (line 29)
[X,FVAL,ATTAINFACTOR] = fgoalattain('objf_1',x0,goal,weight)
Any idea how am I getting this?
It is not a built-in function. You need to install the Optimization toolbox.

Error regarding inlineeval in MATLAB

As part of a group project we have a system of 2 non linear differential equations and we have to draw the S=S(t) , I=I(t) graphic using the midpoint method.
And I'm getting the following error when trying to insert the matrix with the corresponding differential equations:
"Error in inline expression ==> matrix([[-(IS)/1000], [(IS)/1000 - (3*I)/10]])
Undefined function 'matrix' for input arguments of type 'double'.
Error in inline/subsref (line 23)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);"
The code I have done is the following:
syms I S
u=[S;I];
F=[-0.001*S*I;0.001*S*I-0.3*I];
F1=inline(char(F),'I','S');
h=100; %Valores aleatórios
T=100000;
ni=(T/h);
u0=[799;1];
f=zeros(1,2);
k=zeros(1,2);
i=1;
while i<=ni
f(1)=F1(u0(1));
f(2)=F1(u0(2));
dx=h*f;
k(1)=F1((u0(1)+h*(1/2)),(u0(2)+h*(1/2)));
k(2)=F1((u0(1)+h*(1/2)),(u0(2)+h*(1/2)));
u1=u0+h*k;
disp('i:'),disp(i)
disp('u= '),disp(u1)
u0=u1;
i=i+1;
end
I'm new to this so the algorithm it's very likely to be wrong but if someone could help me with that error I'd apreciate it. Thank you!
The problem that specifically creates the error is that you are putting two symbolic functions into a matrix and then calling char (which outputs matrix([[-(IS)/1000], [(IS)/1000 - (3*I)/10]]) rather than converting nicely to string).
The secondary problem is that you are trying to pass two functions simultaneously to inline. inline creates a single function from a string (and using anonymous functions instead of inline is preferred anyway). You cannot put multiple functions in it.
You don't need sym here. In fact, avoid it (more trouble than it's worth) if you don't need to manipulate the equations at all. A common method is to create a cell array:
F{1} = #(I,S) -0.001*S*I;
F{2} = #(I,S) 0.001*S*I-0.3*I;
You can then pass in I and S as so:
F{1}(500,500)
Note that both your functions include both I and S, so they are always necessary. Reconsider what you were expecting when passing only one variable like this: f(1)=F1(u0(1));, because that will also give an error.

Matlab fir1 function error

I'm running Matlab 2014a on Linux and trying to apply a simple FIR filter using the fir1 function. I keep getting the following error, no matter how I try to build the filter:
>>fir1(15,[0.1])
Error using *
Inner matrix dimensions must agree.
>>Error in firls (line 80)
cos_ints = [omega; sin((1:N)' * omega)];
>>Error in fir1 (line 121)
hh = firls(L-1,ff,aa);
I've used the debugger to go to the line of code, and it looks like it's always trying to multiply a column vector of length(order), (1:N)', by another column vector, omega. This doesn't make any sense. Is the fir1 function broken, or am I doing something wrong? This error occurs for me even if I try to run the examples given by MathWorks.
I would guess that Matlab's firls function is masked by another function of the same name, which is in Matlab's path and therefore gets called from fir1.
What do you get when you type :
which firls
? - You should get something which ends in \toolbox\signal\signal\firls.m

Matlab Error: Undefined function 'knnclassify' for input arguments of type 'double'

I am trying to do knnclassify on test_data(10000X784), train_data(50000X784), train_label(50000X1) and k = 1
And I am calling this function as follows:
label = knnclassify(test_data,train_data,train_label,k);
Background:
Where train_label is numeric equivalent digit of the data given in train_data. I want to classify my test_data. The data in both the train and test are in random order, but the train_label totally corresponds with the data in the train_data.
In my friend's workstation it works fine, but in my laptop it gives this error:
Undefined function 'knnclassify' for input arguments of type 'double'.
What could be the reason for the issue and how to solve it? Do I need to install any package? If yes how?
This error means that the function cannot be found in matlab, so you might missing the required toolbox. Just as #schorsch said you need to install the Bioinformatics toolbox.
A way to find out if the function is available in Matlab is typing which knnclassify. The output will be the route where the function resides or 'knnclassify' not found. otherwise.