"Mixed integer class inputs are not supported" Error - matlab

I am working on a project in Matlab and i have to use the gradient function. Following is my code snippet:
im=imread('A.jpg'); //Reads image File
[Ix,Iy]=gradient(rgb2gray(im));
I am Getting the Following error.
Error using bsxfun
Mixed integer class inputs are not supported.
Error in gradient (line 68)
g(2:n-1,:) = bsxfun(#rdivide,(f(3:n,:)-f(1:n-2,:)),h);
I am not able to understand why this error is showing up and how to resolve it.
PS: I know there are many questions posted related to same error but they are due to different causes. I have gone through them but am not to solve my problem.

load an image.
Use rgb2grey if necessary.
Use im2double
Use gradient function, i.e., [fx,fy]=gradient(image)
Use matlab function quiver(fx,fy) to get the result displayed.
Ahsan Latif

You should try [Ix, Iy] = gradient(double(rgb2gray(A))). Or alternatively, as Daniel suggests, use imgradient.

Related

Parfor works with test data but not real data

I am using Matlab 2016a. I have four matrices of size 2044x1572x84 and am trying to regress each column of each matrix to produce a new 2044x1572 matrix of regression coefficients. I need to use parfor; a for loop would take way too long.
When I use the below code using test data (e.g. using rand to make four matrices of 50x50x40) the code executes with no errors. However, when I try using the same code in a cluster with the full 2044x1572x84 matrices I get a transparency violation error with regards to the table: Error using table (line 247) Transparency violation error. I've tried modifying the table code to fix this but only get a suite of other errors.
I'm unsure how to fix the error in this case, particularly given that the success of the code seems to be dependent on the size of the input data. I'm not particularly familiar with parfor, and any feedback on what I may be doing wrong would be greatly appreciated.
COEFF_LST=ones(2044,1572);
parfor i=1:2044
for j=1:1572
ZZ=squeeze(ARRAY_DETREND_L2_LST(i,j,:));
XX=squeeze(ARRAY_DETREND_L2_ONDVI(i,j,:));
YY=squeeze(ARRAY_DETREND_WB_85(i,j,:));
LL=squeeze(ARRAY_DETREND_L2_CNDVI(i,j,:));
T=table(ZZ,XX,YY,LL,'VariableNames',{'LST','ONDVI','DROUGHT','NDVI'});
lm=fitlm(T);
array=table2array(lm.Coefficients);
COEFF_LST(i,j)=array(3,1);
end
end
The table constructor uses inputname under certain circumstances - that can cause transparency violations inside parfor. I realise it's inconvenient, but perhaps you could try "hiding" the table call inside a separate function. I.e.
parfor ...
T = myTableBuilder(ZZ,XX,...);
end
function t = myTableBuilder(varargin)
t = table(varargin{:});
end
In this case I'm getting a transparency error with table, so a simple solution that works is to not use table.
In this case the code would be:
Predictor_Matrix=horzcat(ZZ,XX,YY);
lm = fitlm(Predictor_Matrix,WW);
This works on a cluster without throwing any errors.

Logarithm Matlab

I try to use the logarithm function to a specific base in Matlab but I get the error message:
"Error using log
Too many input arguments." which I do not understand because the syntax is very simple.
My code is: log(4,2);
Why do I get this error?
matlab's log function (before R2017a) doesn't have this functionality.
instead, you can do: log(x)/log(n), whereas log_n(x) = log(x)/log(n)

Adaptive thresholding Matlab-Opencv

I wanted to apply cv.adaptiveThreshold (opencv) through matlab on 8-bit single-channel uint8 image but I am always getting error. I have tried following code from this website: https://kyamagu.github.io/mexopencv/matlab/adaptiveThreshold.html
th = cv.adaptiveThreshold(img,255,'Method',mean,'Type',binary,3,2);
and it gives me the error of Not enough input argument.
when I am running like this:
th = cv.adaptiveThreshold(img);
it is working properly but this is not what I want. I don't want to apply default methods and criteria.
Thanks for the help.
Read the documentation. You are not following the function argument list
cv.adaptiveThreshold(img,'MaxValue',255,'Method','Mean','Type','Binary','BlockSize',3,'C',2);
should work

MATLAB: Error in fig2texPS

I want to use fig2texPS to export plots from MATLAB to LaTeX. I copied the the script to D:\Eigene Dokumente\MATLAB\fig2TexPS and added this folder as a path in MATLAB. Unfortunately, I receive the following error:
>> fig2texPS()
Undefined function 'find' for input arguments of type 'matlab.graphics.chart.primitive.Line'.
Error in fig2texPS (line 526)
lsh = double(find(handle(lshandles),'-class','graph2d.lineseries')); % find plots
PS: I use a version of the script which was updated in order to work with pdtlatex (http://pastebin.com/xK6KxxBT) that I found in the MATLAB Central File Exchange. The same error also occurs when I use the original script.
This might not be the answer you are looking for, but there is the marvelous matlab2tikz that does the job of conversion of figures quite nicely, which you could use as an alternative to fig2texPS.
I also use the function fig2texPS.m and it works very well. It might be an answer for your question to use an older version of Matlab. I am using 2013b and it works. While I have tried this function with Matlab 2015a, I was getting the same error message.
I hope my answer helps you with your problems.

adftest function error in lagmatrix

Using the adftest function in MATLAB's econometrics toolbox, I'm receiving the following error:
>> [h1,pVal1] = adftest(y1,'model','ARD')
Error using lagmatrix (line 25)
lagmatrix: wrong # of input arguments
Error in adftest>runReg (line 705)
yLags = lagmatrix(y,0:(testLags+1));
Error in adftest (line 417)
testReg = runReg(i,y,testT,testLags,testModel,needRegOut);
y1 is a <41x1> vector of doubles.
Has anyone received this error or have any thoughts on what the issue is? I am using this code right out of the box so I'm not sure what is going on. I'd post to MATLAB's site, but it is down for maintenance.
This is either a bug in Matlab, in which case you should submit it on the Matlab support site. Before you do that, you should check that you don't have a function lagmatrix on your path that shadows the built-in function. Type
which lagmatrix
on the command line. If the path does not point to your Matlab installation, you should move lagmatrix off the Matlab search path.
Also note that y1 should not contain all NaN, or be otherwise degenerate, so you may want to check the function using the sample data as suggested in the help to be sure it's a bug and not just your data.
I had the same problem with this function. In my case, the problem was the function lagmatrix (older version) in my MATLAB path and the adftest function was the newest version. The soluction was delete the older version of lagmatrix.