How to fix the Principle Component Analysis error in Matlab - matlab

I happened to a Matlab Problem, the error looks like this:
Error using pca
Too many input arguments.
Error in mdscale (line 413)
[~,score] = pca(Y,'Economy',false);
Error in demo_libsvm_test1 (line 140)
newCoor = mdscale(distanceMatrix,2);
When I debug my code step by step, the error comes from here:
distanceMatrix = pdist(heart_scale_inst,'euclidean'); (line 139)
newCoor = mdscale(distanceMatrix,2); (line 140)
Everything above the two lines are all right. I do not know how to fix the problem. I use Matlab 2014a. Can anyone give me a help?

Related

Issues related to SVR in MATLAB

I am working on support vector regression for aerospace applications. I need to implement SVR in MATLAB. On the internet, I found this link, which gives detailed information with examples. When I try running the example codes in matlab, I am getting this error,
Error using classreg.learning.FitTemplate/fillIfNeeded (line 604)
OptimizeHyperparameters is not a valid parameter name.
Error in classreg.learning.FitTemplate.make (line 124)
temp = fillIfNeeded(temp,type);
Error in RegressionSVM.template (line 349)
temp = classreg.learning.FitTemplate.make('SVM','type','regression',varargin{:});
Error in RegressionSVM.fit (line 343)
temp = RegressionSVM.template(varargin{:});
Error in fitrsvm (line 235)
obj = RegressionSVM.fit(X,Y,varargin{:});
I am using MATLAB R2016a. Kindly let me know, how to solve this issue.
I had a similar issue today. Just upgrade Matlab to Matlab 2016b and it should work. Maybe it's a new parameter that they just introduced.

MATLAB newbie: error using sprintf. Function is not defined for 'matlab.graphics.GraphicsPlaceholder' inputs

Today I tried to run a MATLAB m-file that someone gave me. It works fine for him, but I encountered a warning and errors (below). I am using a Mac with OS X Yosemite (10.10.5) and a new version of MATLAB (R2015b). The person who prepared the m-file would have used an older one and Windows.
From a blog at Mathworks and posts online/here, the error seems to be due to a MATLAB update--a change from using numeric values to point towards graphics objects to using objects themselves. I understand this in theory, but don't know how to fix my code (it has been years since I used MATLAB regularly, so I'm pretty lost).
Warning: Text handle output is not supported when a contour handle
argument is supplied and label placement is automatic.
In clabel (line 214)
In control_volume_20150706>plot_xxx (line 733)
In control_volume_20150706 (line 104)
In run (line 96)
Error using sprintf
Function is not defined for
'matlab.graphics.GraphicsPlaceholder' inputs.
Error in control_volume_20150706>plot_xxx (line 734)
sprintf('%10.4f \n',text_handle);
Error in control_volume_20150706 (line 104) plot_xxx (nr,
xwidevec, yhighvec, omegamat, psimat, umat, vmat, ...
Error in run (line 96) evalin('caller', [script ';']);
This is what the code looks like in the vicinity of line 733:
Line 731 contourlevels = omegamat(1, :) ;
Line 732 [C,h] = contour(X,
Y, flipud(omegamat), contourlevels, 'LineWidth', 2 );
Line 733
text_handle = clabel(C,h);
Line 734 sprintf('%10.4f \n',text_handle);
I would be very grateful for any hints about how to deal with this.
If h is a handle which refers to some object, then in R2015a and later this is the object itself, while in previous versions it's a double which points to an object (as you noted in the question). You can use h.double in R2015a and later to get what would previously be h. E.g., pre-R2015a h = figure(999) would set h to 999, a double; with R2015a and later h is an object and h.double is 999.

Matlab Camera Calibration Toolbox: go_calib_optim error

When I run go_calib_optim on the calibration data I get:
Error using -
Matrix dimensions must agree.
Error in compute_extrinsic_init (line 66)
Y = X_kk - (X_mean*ones(1,Np));
Error in comp_ext_calib (line 22)
[omckk,Tckk] = compute_extrinsic_init(x_kk,X_kk,fc,cc,kc,alpha_c);
Error in go_calib_optim_iter (line 293)
comp_ext_calib;
Error in go_calib_optim (line 56)
go_calib_optim_iter;
Error in calibration_script (line 176)
go_calib_optim;
What could be causing this? Alternatively, is this routine optional? It says it is the main optimization routine but how essential is it? I can afford minor to medium errors in the calibration data.

Imread for .pbm file

I am trying to read an image, but it gives me errors as such. I have tried to read other formats, which work fine. I could not find much online, so I am posting the question here. Any ideas would be helpful!
>> A = imread('C:\Users\5460\Desktop\CV2\Apple\image001.pbm', 'pbm')
Error using impnminfo (line 72)
Invalid magic number. File is not a PPM, PGM, or PBM file.
Error in readpnm (line 25)
info = impnminfo(filename);
Error in imread (line 434)
[X, map] = feval(fmt_s.read, filename, extraArgs{:});
Thanks in advance!

getting complex-valued Jacobian Matrix using NonLinearModel.fit in matlab

I am trying to use the NonLinearModel.fit() function in Matlab to regress two variables. However, I am getting the following error:
Error using internal.stats.getscheffeparam>ValidateParameters
(line 182)
If non-empty, JW must be a numeric, real matrix.
Error in internal.stats.getscheffeparam (line 110)
[J,VF,VP,JW,Intopt,TolSVD,TolE,VQ,usingJ] =
ValidateParameters(J,VF,VP,JW,Intopt,TolSVD,TolE,VQ,allowedIntopt);
Error in nlinfit (line 340)
sch =
internal.stats.getscheffeparam('WeightedJacobian',J(~nans,:),'Intopt','observation','VQ',VQ);
Error in NonLinearModel/fitter (line 1121)
[model.Coefs,~,J_r,model.CoefficientCovariance,model.MSE,model.ErrorModelInfo,~]
= ...
Error in classreg.regr.FitObject/doFit (line 219)
model = fitter(model);
Error in NonLinearModel.fit (line 1484)
model = doFit(model);
Error in getMatrix (line 101)
nlm =
NonLinearModel.fit(regressorMatrix',temp2',modelfun,beta0);
My regressorMatrix is 2-by-N (so the transpose is N-by-2), temp2' is N-by-1, and beta0 and model are given by:
model =#(b,x)b(1).*x(:,1).*x(:,2).^b(2);
beta0=[.14 .6];
nlm = NonLinearModel.fit(regressorMatrix',temp2',model,beta0);
Could someone please help me in figuring out what is causing this error?
EDIT: ok, no help so far so I will try to be more specific. I know that this error is referring to the weighted Jacobian matrix. I am just not sure why this Jacobian would not be real-valued.
Here are the first few rows of my regressor matrix:
regressorMatrix =
1.0e+07 *
0.000000000776613 3.762601240855837
0.000000001683014 3.762601240855837
0.000000001496807 3.762601240855837
0.000000000753495 3.762601240855837
and my response matrix:
temp2 =
-0.011811061934317
0.987582922964869
0.010621342764736
0.135001167018444
0.091950680609212
I can see that something is wrong here (the orders of magnitude in col2 of my regressor matrix are off. I will fix this and get back with an explanation if it turns out to the the cause. I am also working on printing out J. and JW
EDIT2:
I was able to print out JW before the error occurs and discovered that JW is a Nx2 complex matrix. So the specific reason the error is occurring is that the weighted Jacobian matrix is not real valued. Not sure why...
After a lot of digging, I found that the answer to this problem is quite obvious. I didn't realize that some of the values for one of my regressor variables was going negative sometimes. This lead (jumping a few steps ahead) to a complex Jacobian.