Trying to run this code but I keep getting this error - matlab

I want to train an Artificial Neural Network on matlab r2020a for an automatic voltage regulator, I already have a simulink file for my output, but whenever I want to run this code:
I = out.input';
T = out.output';
net=newff(minmax(I),[3,5,1],{'logsig','tansig','purelin'},'trainlm');
net = init(net); % Used to initialize the network (weight and biases)
net.trainParam.show =1; % The result of error (mse) is shown at each iteration (epoch)
net.trainParam.epochs = 10000; % Maximum limit of the network training iteration process (epoch)
net.trainParam.goal =1e-12; % Stopping criterion based on error (mse) goal
net=train(net,I,T); % Start training the network
I keep facing this error:
Unrecognized function or variable 'procInfo'.
Error in nnMex.netHints (line 143)
processingInfoArray = [processingInfoArray procInfo];
Error in nncalc.setup1>setupImpl (line 201)
calcHints = calcMode.netHints(net,calcHints);
Error in nncalc.setup1 (line 16)
[calcMode,calcNet,calcData,calcHints,net,resourceText] = setupImpl(calcMode,net,data);
Error in nncalc.setup (line 7)
[calcMode,calcNet,calcData,calcHints,net,resourceText] = nncalc.setup1(calcMode,net,data);
Error in network/train (line 361)
[calcLib,calcNet,net,resourceText] = nncalc.setup(calcMode,net,data);
Error in ann (line 8)
net=train(net,I,T); % Start training the network
I'm not sure where to start to my search for this problem, but I think it might be a compiler issue
I tried searching online, but all I got was just suggestion to download compilers and toolboxes.

Related

Matlab Meanfreq function with Freqrange

Using the built in function in matlab Meanfreq to calculate the mean frequency of my signal, which is recorded with sensors that have an upper and lower reliable range (70kHz to 500 kHz).
According to the help (https://uk.mathworks.com/help/signal/ref/meanfreq.html#d117e104641) I should be able to specify this reliable range, but when I do this the value MeanFreq returns is outside this range (0.176 kHz) which is clearly not correct.
Anyone know any tips or tricks?
TIA
The code I use w/o the Freqrange is:
Fs = 1e6;
figure()
meanfreq(signal, Fs)
Then with the Freqrange I have
freqrange = [70,500];
Fs = 1e6;
figure()
meanfreq(signal, Fs, freqrange)
If I try
freqrange = [7e4, 5e5];
I get the error:
> Error using psdparserange>parseTime (line 103) The frequency range
> must be within the range of F for the specified input.
Edit - Trying
Fs = 1e6;
figure()
meanfreq(signal, Fs)
figure()
meanfreq(signal,freqrange)
Produces a load of errors.
Error using meanfreq
Expected input number 1, Pxx, to be nonnegative.
Error in psdparserange>parsePSD (line 121)
validateattributes(Pxx,{'numeric'},{'2d','nonnegative'}, funcName,'Pxx',1);
Error in psdparserange (line 40)
[Pxx, F, Frange, rbw] = parsePSD(funcName, varargin{1:min(n,3)});
Error in meanfreq (line 63)
[Pxx, F, Frange, rbw, extraArgs, status] = psdparserange('meanfreq', kaiserBeta, varargin{:});
Error in Main_analysis_Fullsignal (line 30)
meanfreq(signal,freqrange)
I believe this was a compataility issue - once I started using the 2019b version of matlab instead of 2017a I had no problem.

Matlab feature selection

I am trying to learn relevant features in a 300*299 training matrix by taking a random row from it as my test data and applying sequentialfs on it. I have used the following code:
>> Md1=fitcdiscr(xtrain,ytrain);
>> func = #(xtrain, ytrain, xtest, ytest) sum(ytest ~= predict(Md1,xtest));
>> learnt = sequentialfs(func,xtrain,ytrain)
xtrain and ytrain are 299*299 and 299*1 respectively. Predict will give me the predicted label for xtest(which is some random row from original xtrain).
However, when I run my code, I get the following error:
Error using crossval>evalFun (line 480)
The function '#(xtrain,ytrain,xtest,ytest)sum(ytest~=predict(Md1,xtest))' generated the following error:
X must have 299 columns.
Error in crossval>getFuncVal (line 497)
funResult = evalFun(funorStr,arg(:));
Error in crossval (line 343)
funResult = getFuncVal(1, nData, cvp, data, funorStr, []);
Error in sequentialfs>callfun (line 485)
funResult = crossval(fun,x,other_data{:},...
Error in sequentialfs (line 353)
crit(k) = callfun(fun,x,other_data,cv,mcreps,ParOptions);
Error in new (line 13)
learnt = sequentialfs(func,xtrain,ytrain)
Where did I go wrong?
You should build your classifier inside func, not before.
sequentialfs calls the function each time on different sets, and a classifier must be built specifically for each set, using only the features sequentialfs selected for that iteration.
I'm not sure I managed to be clear, in practice you should move the first line of your code inside the body of func
Source: MathWorks

Regression with Categorical Covariates matlab error

I am trying to run the example at:
http://nl.mathworks.com/help/stats/group-comparisons-using-categorical-arrays.html
using Matlab R2013b.
clear
load('carsmall')
cars = table(MPG,Weight,Model_Year);
cars.Model_Year = nominal(cars.Model_Year);
fit = fitlm(cars,'MPG~Weight*Model_Year')
Unfortunatelly I get the error:
Error using classreg.regr.FitObject/assignData (line 257)
Predictor and response variables must have the same length.
Error in classreg.regr.TermsRegression/assignData (line 349)
model = assignData#classreg.regr.ParametricRegression(model,X,y,w,asCat,varNames,excl);
Error in LinearModel.fit (line 852)
model = assignData(model,X,y,weights,asCatVar,dummyCoding,model.Formula.VariableNames,exclude);
Error in fitlm (line 111)
model = LinearModel.fit(X,varargin{:});
Any clue why?

fmincon using SQP algorithm not running

I need to run the optimization of a 2 variables function for which I provide the gradients. The code runs normally for the 'interior-point' algorithm but it stucks after the first interaction when I try the 'sqp' algorithm. The first algorithm gives me 5% of error from the values I expected, so I really need to check if SQP gives me better results.
deltaml=10^(-4);
deltaE=10^(-2);
Eo=[0;1];
Elb=[0;0];
Eub=[100;100000000000];
Alg='sqp'
f1=[subs(fdelta,ml,ml+deltaml);subs(fdelta,E,E+deltaE)];
f2=[subs(fdelta,ml,ml+deltaml/2);subs(fdelta,E,E+deltaE/2)];
gradobj = (4*f2-3*f-f1)./[deltaml;deltaE];
objfungrad = matlabFunction(fdelta,gradobj,'vars',{t},'outputs',{'f','gradf'});
opts_grad=optimset('Algorithm',Alg,'TolFun',1e-16,'TolX',1e-16,'Display','off','GradObj','on');
[xgrad fval] = fmincon(objfungrad,Eo,[],[],[],[],[Elb],[Eub],[],opts_grad);>
The error when running sqp is:
Error using deal (line 38)
The number of outputs should match the number of inputs.
Error in C:\Program
Files\MATLAB\R2013a\toolbox\symbolic\symbolic\symengine.p
Error in C:\Program
Files\MATLAB\R2013a\toolbox\optim\optim\private\evalObjAndConstr.p>evalObjAndConstr
(line 135)
Error in C:\Program
Files\MATLAB\R2013a\toolbox\optim\optim\sqpLineSearch.p>sqpLineSearch
(line 287)
Error in fmincon (line 910)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
sqpLineSearch(funfcn,X,full(A),full(B),full(Aeq),full(Beq), ...
Error in symb_optm_ml_E_mult (line 54)
[xgrad fval] =
fmincon(objfungrad,Eo,[],[],[],[],[Elb],[Eub],[],opts_grad);

Error using Zeros in Matlab while training

I am Trying to train my Neural Network using vInputs and vTargets to create a model net
But I keep getting this irritating Error no matter what I try to correct in my code:
ERROR: Error using zeros.Maximum variable size allowed by the program is exceeded.
I dont find any such big data created by my code and I have a RAM of 4GB
I have 230 images which I need to classify in 3 parts 'Sedan', 'SUV', 'Hatchback'
image size [15x26]
I used this code to convert single image's features extracted by gabor filter to Feature Vector
function IMVECTOR = im2vec (img)
load Gabor;
img = adapthisteq(img);
Features75x208 = cell(5,8);
for s = 1:5
for j = 1:8
Features75x208{s,j} = mminmax(abs(ifft2(G{s,j}.*fft2(double(img),32,32),15,26)));
end
end
Features25x70 = cell2mat(Features75x208);
Features25x70 (3:3:end,:)=[];
Features25x70 (2:2:end,:)=[];
Features25x70 (:,3:3:end)=[];
Features25x70 (:,2:2:end)=[];
IMVECTOR = reshape (Features25x70,[1750 1]);
Now after the feature vector is created I made vInputs using same function for 230 images.
Thus I got
1. vInputs=[1750x230].
2. vTargets=[4x230].
But whenever I run the Project I get error in function.
function net = create_pr_net(inputs,targets)
%CREATE_PR_NET Creates and trains a pattern recognition neural network.
% Create Network
numHiddenNeurons = 35;
net = newpr(inputs,targets,numHiddenNeurons);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train and Apply Network
[net,tr] = train(net,inputs,targets);% <== ERROR OCCURS HERE<==
outputs = sim(net,inputs);
% Plot
plotperf(tr);
plotconfusion(targets,outputs);
save net net
Here is the complete Error:
Error using zeros
Maximum variable size allowed by the program is exceeded.
Error in nnMex2.codeHints (line 117)
hints.TEMP =
zeros(1,ceil(tempSize/8),'double');
Error in nncalc.setup2 (line 13)
calcHints = calcMode.codeHints(calcHints);
Error in network/train (line 306)
[calcLib,calcNet] = nncalc.setup2(calcMode,calcNet,calcData,calcHints);
Error in create_pr_net (line 14)
[net,tr] = train(net,inputs,targets);
Error in executeMe (line 22)
net=create_pr_net(vInputs,vTargets);
Please Help me and ask me if I missed anything and need to specify some more details.
value of tempSize:
EDIT: Well I figured it out that as I am using 32bit system so I can address a maximum of 2^32 = 4.294967e+09 at a time.
While if I was using 64bit I could be able to address about 2^64 = 9.22337e+18 address at a time.
So can you guys give me some idea about how to make it work on my system.