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
Related
I'm using MATLAB 2013a and trying to find peak points of my data. When I tried code example given in
Find Peaks with Minimum Separation
I am getting the following error:
Error using uddpvparse (line 122)
Invalid Parameter/Value pairs.
Error in findpeaks>parse_inputs (line 84)
hopts = uddpvparse('dspopts.findpeaks',varargin{:});
Error in findpeaks (line 59)
[X,Ph,Pd,Th,Np,Str,infIdx] = parse_inputs(X,varargin{:});
I tried simple x and y vectors and got the same error. What can be the problem?
I have the same problem as you (R2013a on OSX) with the example by the Mathworks. For some reason it seems we can't use findpeaks with the x-and y-data as input arguments, We need to call the function with the y data and use the [peaks,locations] output to get the peaks/plot them.
It looks like in R2014b they changed some stuff about findpeaks that does not work with older versions...like calling the function with not output argument in R2014b plots the data/peaks without any additional step...but it does not for earlier versions.
Anyhow here is a way to workaround the problem. Call findpeaks with a single input argument (y data that is, you can use property/value pairs as well) and use the indices (locations) to show the peaks:
clc
clear
load sunspot.dat
year = sunspot(:,1);
avSpots = sunspot(:,2);
[peaks, locations] = findpeaks(avSpots)
plot(year,avSpots)
hold on
scatter(year(locations),avSpots(locations),40,'filled')
hold off
Output:
It might be worthwhile to contact The Mathworks about this. Hope that helps!
I am trying to minimize with respect to a variable "y" a function that contains a parameter which must be calculated as a solution of an equality that contains "y" as well (say, y=-3; in my complete problem it is an equation with no analytic closed form solution, so I really need fzero).
Because of this, I include the fzero function in the argument of fminsearch:
fminsearch( #(y) 10*fzero(#(y) y+3, 0)) ;
I get the error:
Error using fminsearch (line 85)
The input to FMINSEARCH should be either a structure with
valid fields or consist of at least two arguments.
I obviously get the same error with:
f = fzero(#(y) y+3, 0);
fminsearch(#(y) 10*f);
Apparently the problem is that I cannot "nest" a fzero inside fminsearch.
Any idea about how to turn around this problem?
If you read the error message you got and look at the documentation of fminsearch you'll see that you need to call it with two input arguments. You call it with only one.
fminsearch( #(y) 10*fzero(#(x) x+3, 0), 0 )
There seems to be a small problem with my matlabcode.
i'm trying to calculate Qx using this simple formula.
Anybody has an idea what i'm doing wrong?
Error: File: functie5612.m Line: 2 Column: 28
Unexpected MATLAB expression.
Error in oef5612 (line 2)
Qx=functie5612(D)
Define my function
function Qx=functie5612(D)
Qx= D*(11-(0.1*D)/(0.28-D))0.8
end
Initial parameter
D=[0;2;4;6;8;10;12;14;16;18;20;22;23;24;25;26;27;28;30;32;34;36;38]
Using my function
Qx=functie5612(D)
making a graph
clf
figure(1);
plot(D,Qx);
title ('Optimale dilutiesnelheid','FontSize',12);
xlabel('D(1/h)','FontSize',12);
ylabel('Volumetrische biomassaproductiviteit(kg/(m^3*h)','FontSize',12);
legend('Substraat','Product','Biomassa') `
You need the explicit * when doing multiplication. That is, you should have )*0.8 and not just )0.8.
So your function should look like:
function Qx=functie5612(D)
Qx= D*(11-(0.1*D)/(0.28-D))*0.8
end
However, this is still incorrect (dimensions mismatch). If you are looking at elementwise multiplication of D, you will need to use the . operator. The code would look like:
Qx= D.*(11-(0.1*D)./(0.28-D))*0.8
The error you get is due to a matrix dimesion mismatch.
So, you need to use the .* operator instead of *
Qx= D.*(11-(0.1.*D)./(0.28-D)).*0.8;
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.
so if I run this function in matlab
sim1(row,1:512)= ((image(row,1:512,1)-a(1,1)));
it runs fine. now if I modify it to take the square like this
sim1(row,1:512)= ((image(row,1:512,1)-a(1,1)))^2;
it gives me the error, error using ==> mpower
matrix dimensions must agree. Why is this giving me the error, I can do this element by element but I have a lot of data and it will take forever.
It seems you want to do an element by element power which is .^2 not ^2
That is, change to
sim1(row,1:512)= ((image(row,1:512,1)-a(1,1))).^2;