Unable to resolve the name 'handels.EditField' - matlab

this Function told me
Unable to resolve the name 'handels.EditField'.
i am using Matlab App Designer
w = str2double(get(handels.EditField,"string"));
h = str2double(get(handels.EditField2,"string"));
app.m3= imresize(app.m1, [w h]);
cla(app.UIAxes_2);
imshow(app.m3,'Parent',app.UIAxes_2);
i cant find where is the problem

h = str2num(app.EditField.Value);
w = str2num(app.EditField2.Value);
That's the error because the image resizer function takes Int not Double.

Related

Solve equation {exponential *prod exponential(ln)}

I want to solve a equation in MATLAB with fsolve
I'm trying to do that:
function F = root2d(P);
lambda = 2*10^-4;
th = -40:-1:-106;
PL1 = 10471285.480509; % (mw)
p1 = 10;
p2 = 6 ;
p3 = 8 ;
al = 2.5;
T = 10.^(th./10);
r = (p1*PL1^(-1)./T).^(1/al);
R = (p2*PL1^(-1)./T).^(1/al);
syms P
c = (lambda.*pi.*(R.^2));
j = 1:3;
D = zeros(3,67);
for k = 1:numel(j)
F(1) = (prod(D(k,:)==exp(P(1).*c.*(log(P(1)).^k/factorial(k))))).*exp(-(lambda*P(1).*pi.*(r.^2)))-P;
end
fun = #root2d;
P0 = 0;
P = fsolve(fun,P0)
Do you have an idea?
There are a couple of problems in this code. I will help you with the most tricky.
It is identified using rubberduck debugging. Let me exemplify it by explaining your code to you.
Starting from the top you define a function called root2d, which returns some object F, then in this function you define alot of constants. With these cosntants defined, you can define your symbolic function F, which we earlier saw was the output of the function. Continuing in this function, root2d, you now create a function handle fun to root2d, and then in the last line you call fsolve to solve fun.
Did you see the error?
fsolve calls fun which is a function handle to root2d. Thus fsolve calls root2d. Running root2d MATLAB comes across a new fsolve which calls root2d. I.e. root2d will be pushed unto the stack over and over again.
This is solved by taking the last three lines out of the function, and then running them from another script or from the terminal.
Doing so results in a new error:
Unable to perform assignment because the indices on the left side are
not compatible with the size of the right side.
Error in sym/privsubsasgn (line 1085)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 922)
C = privsubsasgn(L,R,inds{:});
Error in SO (line 18)
F(1) = (prod(D(k,:)==exp(P(1).*c.*(log(P(1)).^k/factorial(k))))).*exp(-(lambda*P(1).*pi.*(r.^2)))-P;
Error in fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot
continue.
I.e. you have to ensure that your objective function, F(1) =... is correctly written.

Receiving MATLAB Error Regarding Function Arguments

When running my MATLAB script below, I keep getting an error that states:
Error using spa (Line 147)
The value of the window
size must be an integer greater than 2.
Error in "projectName" G = spa(xFunction2, x)
I've tried putting in multiple types of arguments into "spa" (data, windowsize, frequency) but it still yields the same error(s). Help?
n = 1:1024;
%Signal Function
xFunction = sqrt(10)*exp(j*2*pi*0.10*n)+ sqrt(20)*exp(j*2*pi*0.20*n) + sqrt(625);
%Complex Noise Function
zFunction = 0.707*randn(size(n)) + j*0.707*randn(size(n));
%Computing the value of x(n) + sqrt(625)*z
xFunction2 = xFunction + sqrt(625)*zFunction;
G = spa(xFunction2,51);
figure(1);
plot(w, 10*log10(G));
Acording the documentation of spa the first argument is iddata type. In addition, the time serie has to be a column vector.
So, to make it works change G = spa(xFunction2,51); for G = spa(xFunction2(:),51);. To do it the correct way, convert your time serie to iddata:
Ts = 0.1; % what ever is your sampling time.
myiddata = iddata(xFunction2(:),[],Ts);
G = spa(myiddata,51);
In addition, you should use spectrum(G) or bode(G)to plot the result.

matlab - symbol order in qammod

I'm trying to simulate QAM with arbitrary symbol mapping.
Matlab help page says I just need to use the format: y =qammod(x,M,symOrder).
M=16;k = log2(M);n = 10000;dataIn = randi([0 1],n,1);
dataInMatrix = reshape(dataIn,length(dataIn)/k,k);
dataSymbolsIn = bi2de(dataInMatrix);
vec = randperm(16)-1;
dataMod = qammod(dataSymbolsIn,M,0,vec);
Matlab returns error 'Invalid symbol set ordering.'
I'm wondering if this is a problem with Matlab version since help page is for 2016a but school computer has 2015b.

How do I make simulation/optimization work in Matlab?

I am trying to link SimEvent and the optimization module of MATLAB. For that, I first need to define a function that runs the simulation then call it in an optimization function. I got the idea of the simulation/optimization code from the link below:
http://au.mathworks.com/videos/optimizing-manufacturing-production-processes-68961.html
I tried to go through all the code I see in this video but, when I am applying it, it is not working. Here is my code:
function finalresults = SimOpt ()
intcon = [1];
A=[];
b=[];
Aeq=[];
beq = [];
lb = [1];
ub= [10];
finalresults= intlinprog(#f,intcon,A,b,Aeq,beq,lb,ub);
function obj = f(vecX)
NumServers = vecX(1);
NumTruck = vecX(2);
set_param('concreting10/Positioning and Unloading','NumberOfServers',num2str(NumServers));
set_param('concreting10/Washing','NumberOfServers',num2str(NumTruck));
simOut = sim('concreting10','SaveOutput','on','OutputSaveName','WaitingTimeInQueue');
z = simOut.get('WaitingTimeInQueue');
waiting = max(z);
cost = [100 200]*vecX';
obj = waiting*1000+cost;
end
end
When I run the whole code I get this warning:
Error using intlinprog (line 122) INTLINPROG requires the following inputs to be of data type double: 'f'.
Error in SimOpt (line 26) finalresults= intlinprog(#f,intcon,A,b,Aeq,beq,lb,ub);
Any help will be appreciated.
Change the last line in the function to
obj = waiting * 1000.0 + cost
MATLAB and many other HLLs convert data type to integer if multiplied by an integer type constant value. So it is necessary to multiply the constant as double type by adding a decimal point.

MATLAB fminsearch optimization error

I want to optimize x value in the following equation
formula_1=((x(1)+x(2).*exp(-TR./x(3)))./(1+cos(time_stamps).* exp(-TR./x(3))));
diff =#(x)sum((formula_1-img_vol).^2);
[pa,fval,exfl]= fminsearch(diff,startingvals,opts);
startingvals=[1,1,0.1];
opts = optimset('Display','off','TolFun',1e-9,'TolX',1e-9);
img_vol = 32x32x11 vector.
These all I am doing in the main script file. But the error comes out is
Error in fminsearch (line 191)
fv(:,1) = funfcn(x,varargin{:});
Error in biexp_main (line 65)
[pa,fval,exfl]=fminsearch(diff,startingvals,opts);
Kindly help me what I suppose to do??
It is rather difficult to reproduce your error since there is many information missing. (What is the exact error? What are the sizes of TR and time_stamps?).
What should help is:
change your function diff so that it returns a scalar if this is currently not the case (check with diff(startginvals)). Maybe change it to sum(sum(sum(.))).
As indicated in the comments: diff is independent from x in the current form. The 'indirect contribution' you mention does not work: it considers formula_1 and hence x as constant.
Putting this together, try:
TR = rand; %?
time_stamps = rand; %?
img_vol = rand(32,32,11);
formula_1 = #(x) (x(1)+x(2).*exp(-TR./x(3))) ./ (1+cos(time_stamps).*exp(-TR./x(3)));
diff = #(x) sum(sum(sum((formula_1(x)-img_vol).^2)));
opts = optimset('Display','off','TolFun',1e-9,'TolX',1e-9);
startingvals=[1,1,0.1];
[xOpt,diffOpt] = fminsearch(diff,startingvals,opts);