matlab answers -凯发k8网页登录
https://ww2.mathworks.cn/matlabcentral/answers/questions?status=unanswered
matlab answers -凯发k8网页登录
2023-06-08t06:32:16z
tag:ww2.mathworks.cn,2005:question/1979989
2023-06-08t06:32:16z
2023-06-08t06:32:16z
how to regulate variable dc voltage by chopper circuit or other ways?
i'm going to do my thesis titled "regulation of electric power for a unique riverine hydrokinetic energy system." i'm now looking for a simulink model to regulate variable dc output (comes from a converter/rectifier) using a chopper circuit or any other ways. then this regulated dc voltage will be sent to a inverter to be converted into 3-phase ac voltage. please help me with this if there is any simulink model for this problem. also, please share if you have any idea to resolve this problem. thanks in advance.
kawsar
https://ww2.mathworks.cn/matlabcentral/profile/authors/27282806
tag:ww2.mathworks.cn,2005:question/1979979
2023-06-08t06:26:19z
2023-06-08t06:26:19z
wlanhdlreceiver use only 64 sample to do fine symbol timming. is it enough for 40m, 80m and 16mhz wlan signal?
i am learning on the wlanhdlreceiver hdl design. the design uses 64 data to do fine symbol timing. but in matlab .m reference design, it uses entire lltf signal to do fine symbol timing. it means for 40mhz, or 80mhz wlan signal, it will use 128 or 256 samples. do you think the wlanhdlreceiver taking only 64 sample to do fine symbol timing will have performance issue at 40m, 80m, or 160mhz wlan signal?
xiaodong yu
https://ww2.mathworks.cn/matlabcentral/profile/authors/14842246
tag:ww2.mathworks.cn,2005:question/1979974
2023-06-08t06:19:36z
2023-06-08t06:19:36z
how to read data type conversion block name using mscript
how to read data type conversion block name using mscript
i used the below script but it was not working
blockpaths = find_system('h217a_power_supply','type','data type conversion');
vignesh s
https://ww2.mathworks.cn/matlabcentral/profile/authors/30303717
tag:ww2.mathworks.cn,2005:question/1979969
2023-06-08t05:59:58z
2023-06-08t05:59:58z
how in simulink send one signal from an input to one of several outputs according to a given output number?
simulink has a "multi-port switch" element that can be used to switch one of the inputs to a single output.
it is necessary to solve the inverse problem:
to switch the only input signal to the selected output of 10 possible.
how it is better to implement it?
ps
the option with element "output switch" does not work. error "invalid connection between message and signal ports"
alex k
https://ww2.mathworks.cn/matlabcentral/profile/authors/17317181
tag:ww2.mathworks.cn,2005:question/364378
2017-11-01t02:08:24z
2023-06-08t05:49:40z
how do i turn the rankine cycle simscape model example provided by mathlab into organic rankine cycle to use different fluid properties other than water
-i ran ssc_rankine_cycle
-i changed 'steam properties block' into fluid properties
-with the help of 2-phase fluid tables, i filled in the fluid property block with properties of benzene
-now i need to change p_initial and t_initial of all the blocks through trial and error in order to avoid simulation errors
-is there a better way of simulating different fluid properties in this model without much hassle?
surrentther sukumaran
https://ww2.mathworks.cn/matlabcentral/profile/authors/10993321
tag:ww2.mathworks.cn,2005:question/1978434
2023-06-05t10:49:39z
2023-06-08t04:58:04z
use of fminimax function to solve minimax game
when i am using the fminimax function i am getting the same answer when i provide the different values of lambda. i have defined my utility function as different .m file.
�fine the parameters and constants
n = 5; % number of rows
m = 4; % number of columns
% define the matrices r, p, and d (example values)
r0= [1, 1, 1, 1; 1, 1, 1, 1; 1, 1, 1, 1; 1, 1, 1, 1; 1, 1, 1, 1]; % n x m matrix
lambda= [0.02, 0.02, 0.02, 0.02; 0.02, 0.02, 0.02, 0.02;
0.02, 0.02, 0.02, 0.02; 0.02, 0.02, 0.02, 0.02;
0.02, 0.02, 0.02, 0.02]; % n x m matrix
d= [33, 38, 5, 38; 2, 15, 3, 4;
19, 29, 13, 7; 7, 45, 43, 19;
25, 22, 15, 25];
c0=[299, 253, 196, 227, 204]; initial guess
u=utility_3(r0,lambda,c0,d,n,m);
f=@utility_3;
lb = [0,0,0,0,0]; % lower bounds
ub = [300,300,300,300,300]; % upper bounds
aeq=[1,1,1,1,1]; %coefficient vector of ci
beq=[394]; %budget
[c, fval,maxfval,output] = fminimax(f, c0, [], [], aeq, beq, lb, ub);
% print the optimal solution and objective value
disp('allocation:');
disp(c);
disp('expected loss:');
disp(fval);
disp('maximum expected loss and attack strategy');
disp(max(fval,[],2));
akshay tanaji bhosale
https://ww2.mathworks.cn/matlabcentral/profile/authors/17661447
tag:ww2.mathworks.cn,2005:question/1979814
2023-06-07t17:15:51z
2023-06-08t04:39:00z
old simulink models wont run in 2023a, requires aerospace toolbox, did not before
all older versions of our simulink model do not run in 2023a due to wanting aerospace toolbox. we do not have that tool box and we have never had it. we have not changed the simulink model. how can i get my model functional again? i have tried openeing in 2023a and saving to older format and repoening but it still flags the blocks as needing aerospace blockset/toolbox. thank you very much!
valerie
https://ww2.mathworks.cn/matlabcentral/profile/authors/28516695
tag:ww2.mathworks.cn,2005:question/498568
2019-12-31t21:38:15z
2023-06-08t04:31:03z
sysgen license checkout failed.
i am working on xilinx system generator.
i get an error when run my simulink block-
sysgen license checkout failed.
xilinxd_license_file = d:\xilinx\2017_xilinx\xilinx.lic;c:/xilinx/vivado/2017.4/data/sysgen/hwcosim_compiler/pp_ethernet
lm_license_file = xilinx
license search path: c:\users\sandip\appdata\roaming\xilinxlicense;c:\.xilinx;d:\xilinx\2017_xilinx\xilinx.lic;c:\xilinx\vivado\2017.4\data\sysgen\hwcosim_compiler\pp_ethernet;xilinx;c:\xilinx\vivado\2017.4\data\ipcore_licenses
i have already go through the xilinix manage license tab and reset the license path...but still got the error..please solve the error
sandip paul
https://ww2.mathworks.cn/matlabcentral/profile/authors/16932120
tag:ww2.mathworks.cn,2005:question/1979954
2023-06-08t04:19:40z
2023-06-08t04:26:44z
error during gan training : render process terminated: null java.lang.nosuchfielderror: ts_process_oom
the following error occurred during gan training:
error message:
render process terminated: null
java.lang.nosuchfielderror: ts_process_oom
--detailed information--
system: hp z4 workstation, memory: 128gb, ssd: 1tb (50% is available)
operating system: windows 10, 64-bit
matlab version: r2022b
java heap space: 32.697gb
execution file: example file from matlab, traingenerativeadversarialnetwork(gan)example
i think java heat space is enough because the system memory usage is below 20gb and java heap space setting is over 32gb.
please, let me know how to solve this problem.
mo
https://ww2.mathworks.cn/matlabcentral/profile/authors/20190775
tag:ww2.mathworks.cn,2005:question/1978609
2023-06-05t14:34:27z
2023-06-08t03:37:30z
eigen value of stochastic matrix
i wan to find eigen values and eigen vector of a stochastic matrix using newton raphson method.
% define the dimensions and variables
n = 3; % size of vectors and matrices
m = 2; % number of matrices
p = 4; % number of eigenvalues and tensors
maxiterations = 100; % maximum number of iterations
tolerance = 1e-6; % tolerance for convergence
% initialize variables
u = ones(n*p, 1); % initial guess for u, each column represents u1, u2, ..., up
lambda = ones(p, 1); % initial guess for lambda, each element represents lambda1, lambda2, ..., lambdap
% define the matrices and tensors
c0 = eye(p); % example: identity matrix
a0 = magic(n); % example: identity matrix
c = rand(p, p, m); % example: random p x p x m tensor
a = rand(n, n, m); % example: random n x n x m tensor
e = rand(p, p, p); % example: random p x p x p tensor
ca=0;
for i=1:m
ca= ca kron(c(:,:,i),a(:,:,i));
end
% perform newton-raphson iteration
for iter = 1:maxiterations
% compute the left-hand side of the equation
lhs = (kron(c0 , a0) ca) * u;
% compute the right-hand side of the equation
lame=0;
for p = 1:p
lame = lame kron(lambda(p) * e(:, :, p),eye(n)) ;
end
rhs=lame*u
% compute the residual and check for convergence
residual_1 = lhs - rhs;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% initialize the variables
i=eye(n,n);
ca1=zeros(p,1);
for i=1:p
ca1(i)= u'*kron(e(:,:,i),i)*u;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
residual_2=ca1;
% compute the residual and check for convergence
residual = [residual_1;residual_2];
if norm(residual(:)) < tolerance
disp('converged!');
break;
end
jacobian = jac_1(a,lambda , u, n,m,p);
% update u and lambda using the newton-raphson method
delta = jacobian \ residual(:);
u = u - delta(1:n*p);
lambda = lambda - delta(n*p 1:end);
% display the current iteration and residual
disp(['iteration: ' num2str(iter) ', residual: ' num2str(norm(residual(:)))]);
end
uf=reshape(u,n,[])
lambdaf=lambda
but the answer i am getting is
lambdaf =
1.0e 58 *
2.7709
-1.9052
0.3483
-0.3253.
it would be very helpful if someone help me improve this code
rakesh kumar
https://ww2.mathworks.cn/matlabcentral/profile/authors/15908659
tag:ww2.mathworks.cn,2005:question/1979949
2023-06-08t03:13:11z
2023-06-08t03:13:11z
how can i interface my texas instrument dsp with available can communication through simulink
hello all,
i have a tif28379d board that is operating an motor drive. there is can interface in the motordrive. is it possible to control the can or establish link through simulink with can and dsp at the same time? the can communication supports national instrument driver.
thanks for the help.
ashik
ashik amin
https://ww2.mathworks.cn/matlabcentral/profile/authors/15796878
tag:ww2.mathworks.cn,2005:question/1645380
2022-02-08t09:34:56z
2023-06-08t02:56:39z
java.lang.illegalargumentexception: ntfs ads separator (':') in file name is forbidden
when i perform coder with single precision conversion using fixed point designer, during mex building, following errors happn.but when i perform coder without precision conversion, no error happens. how can i fix this problem?
exception in thread "awt-eventqueue-0": java.lang.illegalargumentexception: ntfs ads separator (':') in file name is forbidden.
at org.apache.commons.io.filenameutils.indexofextension(filenameutils.java:746)
at org.apache.commons.io.filenameutils.getextension(filenameutils.java:1069)
at com.mathworks.toolbox.coder.nide.editor.coderfilebackingstore.(coderfilebackingstore.java:38)
at com.mathworks.toolbox.coder.nide.editor.coderfilebackingstore.(coderfilebackingstore.java:30)
at com.mathworks.toolbox.coder.nide.nideartifactset.addsourceartifact(nideartifactset.java:69)
at com.mathworks.toolbox.coder.nide.impl.codernidefacade.updateartifactset(codernidefacade.java:339)
at com.mathworks.toolbox.coder.nide.impl.codernidefacade.initfilestomodel(codernidefacade.java:304)
at com.mathworks.toolbox.coder.nide.impl.codernidefacade.access$800(codernidefacade.java:63)
at com.mathworks.toolbox.coder.nide.impl.codernidefacade$4.propertychange(codernidefacade.java:207)
at java.beans.propertychangesupport.fire(propertychangesupport.java:335)
at java.beans.propertychangesupport.firepropertychange(propertychangesupport.java:327)
at java.beans.propertychangesupport.firepropertychange(propertychangesupport.java:263)
at com.mathworks.toolbox.coder.nide.impl.codernideappmodel.fireinputfileschanged(codernideappmodel.java:175)
at com.mathworks.toolbox.coder.nide.impl.codernideappmodel.setinputfiles(codernideappmodel.java:171)
at com.mathworks.toolbox.coder.wfa.build.verifycompatibilitymodel$normalmexbuilder$1.handlefiles(verifycompatibilitymodel.java:534)
at com.mathworks.toolbox.coder.wfa.build.coderbuildmanager$handler$1.run(coderbuildmanager.java:250)
at com.mathworks.mwswing.mjutilities.runoneventdispatchthread(mjutilities.java:911)
at com.mathworks.toolbox.coder.wfa.build.coderbuildmanager$handler.buildfinished(coderbuildmanager.java:247)
at com.mathworks.toolbox.coder.wfa.build.buildcommand$1$1.run(buildcommand.java:211)
at java.awt.event.invocationevent.dispatch(invocationevent.java:311)
at java.awt.eventqueue.dispatcheventimpl(eventqueue.java:758)
at java.awt.eventqueue.access$500(eventqueue.java:97)
at java.awt.eventqueue$3.run(eventqueue.java:709)
at java.awt.eventqueue$3.run(eventqueue.java:703)
at java.security.accesscontroller.doprivileged(native method)
at java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(protectiondomain.java:74)
at java.awt.eventqueue.dispatchevent(eventqueue.java:728)
at java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:205)
at java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:116)
at java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:105)
at java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:101)
at java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:93)
at java.awt.eventdispatchthread.run(eventdispatchthread.java:82)
adelie penguin
https://ww2.mathworks.cn/matlabcentral/profile/authors/19968904
tag:ww2.mathworks.cn,2005:question/1979939
2023-06-08t02:32:23z
2023-06-08t02:32:23z
visadev autoly continously send '*idn?'. get thousands of lines of the return of '*idn?'
i have a optical spetrum whose name is ando aq6317. after use ni gpib-usb-hs connect it with my windows server, with matlab 2021b and a package of i"nstrument control toolbox support package for national instruments visa and icp interfaces 21.2.1".
i use the v = visadev('gpib0::1::0::instr')
can successfully coonect.
but the problem is, the device will repeatedly send the instrument info string. with thousands of lines, times. the content is the same as the querying output of "*idn?".
and i can see the v.numbytesavailable exponentially surge. within the time i did nothing.
i use read(v,v.numbytesavailable,"char") to watch and everything is the querying output of '*idn?'
so i really doubt that the visadev has a bug of autoly continously send '*idn?'.
other instruments like keysight awg 8194 i tried, tek osc or awg will not occur this problem.
how to do???
although i found use old method g1=gpib('ni',0, 1);
can avoid the bug. but i do not wanna write two type of visa codes. for my previous codes are all based on visadev!!!!!!!!!!!!
long
https://ww2.mathworks.cn/matlabcentral/profile/authors/14345967
tag:ww2.mathworks.cn,2005:question/1979934
2023-06-08t02:17:47z
2023-06-08t02:17:47z
is it possible to make windows desktop pc to a master host for ethercat network?
i want to control 3 actuators (orientalmotor) using an orientalmotor multi-axis driver that works with ethercat, and i'm trying to make a hils approach using simulink.
for this case, i was thinking on using a speedgoat device as slave.
my question lies in how can i make my desktop pc into a master device that runs with ethercat network in order to control these actuators?
giancarlo guerra padilla
https://ww2.mathworks.cn/matlabcentral/profile/authors/25995462
tag:ww2.mathworks.cn,2005:question/1979914
2023-06-07t23:57:06z
2023-06-07t23:57:06z
matlab coder returning non specific issue description during check for runtime issues step
hello,
for use in a student project, i am attempting to convert an audio-based transmitter/receiver function from matlab to c/cpp.
i went through the process of correcting various issues, brought up by the matlab coder tool.
however, the latest issue brought up by the "check for run-time issues" step does not mention any line / sub-function in the code. instead, it simply states:
" insufficient number of outputs from right hand side of equal sign to satisfy assignment.
use help codegen for more information on using this command.
insufficient number of outputs from right hand side of equal sign to satisfy assignment."
i do not know where in the code this issue is located, and given the project size, i would prefer not to start looking with no clear leads.
the function i am trying to convert is running correctly, and no issues are found before the runtime issues check (input types, %#codegen, etc.).
any help in accessing a more detailed error message / pointing me in the right direction would be greatly appreciated.
thanks (:
jonathan
jonathan elgavi
https://ww2.mathworks.cn/matlabcentral/profile/authors/17906028
tag:ww2.mathworks.cn,2005:question/1979909
2023-06-07t23:29:08z
2023-06-07t23:31:42z
how do i add a unique id to the the graph in can explorer in the vehicle network toolbox?
hello! i pulled some can data into vehicle network toolbox/can explorer and was hoping to be able to visualize it using the graph. i found a video on how to add a signal to the graph but it involved having a dbc file (and i didn't see an example document/format of how i would create said dbc file). is there a way to add a signal to the graph any other way? i tried going through the menus and couldn't find a way to do it and dragging/dropping, and right clicking don't seem to get me anywhere either.
any info on how i can take a signal and add it to a graph would be greatly appreciated. if there's not an easy way to do so (that might be a feature request at that point), is there an example dbc format or can i see an example if i wanted to add, say, signals with ids for 0x18d, 0x224, and 0x27a (i have a bunch i want to add but once i see an example, i can put one together myself)? thanks!
jeremy
https://ww2.mathworks.cn/matlabcentral/profile/authors/29463111
tag:ww2.mathworks.cn,2005:question/1979894
2023-06-07t21:51:14z
2023-06-07t22:31:16z
setting up graphic user interface
as i have never set up a gui interface i am trying to find out how to do all the call backs correctly. i have included the program i wrote in script editor and the gui code program and a screen shot of the design of the gui. my question is can the radio buttons be used with the code i wrote in editor with all the different loops that i have and if so how do i do that code? if the radio buttons can not work that way is there a better choice?
%program in editor
clear
clc
f=input('gasoline or diesel: ','s');
c=input('number of engine cylinders ');
t=input('trailer being towed yes or no: ','s');
tw=input('trailer weight ');
m=input('trip length in miles ');
c=input('cost of fuel per gallon ');
switch f
case 'gasoline'
if c==4
bmpg=24;
switch t
case 'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.2);
elseif tw>2000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=24;
end
elseif c==6
bmpg=18;
switch t
case 'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.1);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.2);
elseif tw>4000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=18;
end
elseif c==8
bmpg=12;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.05);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.1);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.2);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.4);
elseif tw>8000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=12;
end
end
case 'diesel'
if c==4
bmpg=26;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.05);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.1);
elseif tw>4000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=26;
end
elseif c==6
bmpg=22;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.025);
elseif tw>2000 && tw<=4000
mpg=bmpg-(mbpg*0.5);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.1);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.2);
elseif tw>8000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=22;
end
elseif c==8
bmpg=18;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.0125);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.05);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.2);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.4);
elseif tw>8000 && tw<10000
mpg=bmpg-(bmpg*0.6);
elseif tw>10000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=18;
end
end
end
fprintf('miles per gallon')
disp(mpg)
g=(m/mpg);%%how many gallons used
fprintf('how many gallons of fuel used')
disp(g)
cf=g*c;%%cost to fuel up
fprintf('cost to fuel up')
disp(cf)
cm=(g/m)*c;%%cost per mile
fprintf('cost per mile')
disp(cm)
x=cf:1:cm;
y=bmpg:1:mpg;
%gui program
classdef jonpagelsprojectgui < matlab.apps.appbase
% properties that correspond to app components
properties (access = public)
uifigure matlab.ui.figure
gridlayout matlab.ui.container.gridlayout
leftpanel matlab.ui.container.panel
editfield matlab.ui.control.numericeditfield
numberofenginecylindersbuttongroup matlab.ui.container.buttongroup
button_8 matlab.ui.control.radiobutton
button_6 matlab.ui.control.radiobutton
button_4 matlab.ui.control.radiobutton
trailertowedbuttongroup matlab.ui.container.buttongroup
nobutton matlab.ui.control.radiobutton
yesbutton matlab.ui.control.radiobutton
fueltypebuttongroup matlab.ui.container.buttongroup
dieselbutton matlab.ui.control.radiobutton
gasolinebutton matlab.ui.control.radiobutton
tripinmileseditfield matlab.ui.control.numericeditfield
tripinmileseditfieldlabel matlab.ui.control.label
trailerweighteditfield matlab.ui.control.numericeditfield
trailerweighteditfieldlabel matlab.ui.control.label
costpergallonslider matlab.ui.control.slider
costpergallonsliderlabel matlab.ui.control.label
centerpanel matlab.ui.container.panel
plotbutton matlab.ui.control.button
calculatebutton matlab.ui.control.button
rightpanel matlab.ui.container.panel
costmileeditfield matlab.ui.control.numericeditfield
costmileeditfieldlabel matlab.ui.control.label
costtofuelupeditfield matlab.ui.control.numericeditfield
costtofuelupeditfieldlabel matlab.ui.control.label
gallonsofusedfueleditfield matlab.ui.control.numericeditfield
gallonsofusedfueleditfieldlabel matlab.ui.control.label
milesgalloneditfield matlab.ui.control.numericeditfield
milesgalloneditfieldlabel matlab.ui.control.label
uiaxes matlab.ui.control.uiaxes
end
% properties that correspond to apps with auto-reflow
properties (access = private)
onepanelwidth = 576;
twopanelwidth = 768;
end
% callbacks that handle component events
methods (access = private)
% value changed function: costpergallonslider
function costpergallonslidervaluechanged(app, event)
c = app.costpergallonslider.value;
app.editfield.value=c;
end
% selection changed function: fueltypebuttongroup
function fueltypebuttongroupselectionchanged(app, event)
f=app.fueltypebuttongroup.selectedobject;
switch f
case app.gasolinebutton
case app.dieselbutton
end
end
% selection changed function: numberofenginecylindersbuttongroup
function numberofenginecylindersbuttongroupselectionchanged(app, event)
c = app.numberofenginecylindersbuttongroup.selectedobject;
switch c
case app.button_4
case app.button_6
case app.button_8
end
end
% value changed function: trailerweighteditfield
function trailerweighteditfieldvaluechanged(app, event)
tw = app.trailerweighteditfield.value;
end
% value changed function: tripinmileseditfield
function tripinmileseditfieldvaluechanged(app, event)
m = app.tripinmileseditfield.value;
end
% button pushed function: calculatebutton
function calculatebuttonpushed(app, event)
m = app.tripinmileseditfield.value;
tw = app.trailerweighteditfield.value;
f=app.fueltypebuttongroup.selectedobject;
t = app.trailertowedbuttongroup.selectedobject;
switch f
case 'gasoline'
case c==4
bmpg=24;
switch t
case 'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.2);
elseif tw>2000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=24;
end
case c==6
bmpg=18;
switch t
case 'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.1);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.2);
elseif tw>4000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=18;
end
case c==8
bmpg=12;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.05);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.1);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.2);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.4);
elseif tw>8000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=12;
end
end
case 'diesel'
case c==4
bmpg=26;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.05);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.1);
elseif tw>4000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=26;
end
case c==6
bmpg=22;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.025);
elseif tw>2000 && tw<=4000
mpg=bmpg-(mbpg*0.5);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.1);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.2);
elseif tw>8000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=22;
end
case c==8
bmpg=18;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.0125);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.05);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.2);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.4);
elseif tw>8000 && tw<10000
mpg=bmpg-(bmpg*0.6);
elseif tw>10000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=18;
end
end
end
app.milesgalloneditfield.value=mpg;
app.gallonsofusedfueleditfield.value=g;
app.costmileeditfield.value=cm;
app.costtofuelupeditfield.value=cf;
end
% selection changed function: trailertowedbuttongroup
function trailertowedbuttongroupselectionchanged(app, event)
t = app.trailertowedbuttongroup.selectedobject;
switch t
case app.yesbutton
case app.nobutton
end
end
% value changed function: milesgalloneditfield
function milesgalloneditfieldvaluechanged(app, event)
app.milesgalloneditfield.value=mpg;
end
% value changed function: gallonsofusedfueleditfield
function gallonsofusedfueleditfieldvaluechanged(app, event)
app.gallonsofusedfueleditfield.value=g;
end
% value changed function: costtofuelupeditfield
function costtofuelupeditfieldvaluechanged(app, event)
app.costtofuelupeditfield.value=cf;
end
% value changed function: costmileeditfield
function costmileeditfieldvaluechanged(app, event)
app.costmileeditfield.value=cm;
end
% changes arrangement of the app based on uifigure width
function updateapplayout(app, event)
currentfigurewidth = app.uifigure.position(3);
if(currentfigurewidth <= app.onepanelwidth)
% change to a 3x1 grid
app.gridlayout.rowheight = {517, 517, 517};
app.gridlayout.columnwidth = {'1x'};
app.centerpanel.layout.row = 1;
app.centerpanel.layout.column = 1;
app.leftpanel.layout.row = 2;
app.leftpanel.layout.column = 1;
app.rightpanel.layout.row = 3;
app.rightpanel.layout.column = 1;
elseif (currentfigurewidth > app.onepanelwidth && currentfigurewidth <= app.twopanelwidth)
% change to a 2x2 grid
app.gridlayout.rowheight = {517, 517};
app.gridlayout.columnwidth = {'1x', '1x'};
app.centerpanel.layout.row = 1;
app.centerpanel.layout.column = [1,2];
app.leftpanel.layout.row = 2;
app.leftpanel.layout.column = 1;
app.rightpanel.layout.row = 2;
app.rightpanel.layout.column = 2;
else
% change to a 1x3 grid
app.gridlayout.rowheight = {'1x'};
app.gridlayout.columnwidth = {475, '1x', 378};
app.leftpanel.layout.row = 1;
app.leftpanel.layout.column = 1;
app.centerpanel.layout.row = 1;
app.centerpanel.layout.column = 2;
app.rightpanel.layout.row = 1;
app.rightpanel.layout.column = 3;
end
end
end
% component initialization
methods (access = private)
% create uifigure and components
function createcomponents(app)
% create uifigure and hide until all components are created
app.uifigure = uifigure('visible', 'off');
app.uifigure.autoresizechildren = 'off';
app.uifigure.position = [100 100 970 517];
app.uifigure.name = 'matlab app';
app.uifigure.sizechangedfcn = createcallbackfcn(app, @updateapplayout, true);
% create gridlayout
app.gridlayout = uigridlayout(app.uifigure);
app.gridlayout.columnwidth = {475, '1x', 378};
app.gridlayout.rowheight = {'1x'};
app.gridlayout.columnspacing = 0;
app.gridlayout.rowspacing = 0;
app.gridlayout.padding = [0 0 0 0];
app.gridlayout.scrollable = 'on';
% create leftpanel
app.leftpanel = uipanel(app.gridlayout);
app.leftpanel.foregroundcolor = [1 0 0];
app.leftpanel.backgroundcolor = [0.8 0.8 0.8];
app.leftpanel.layout.row = 1;
app.leftpanel.layout.column = 1;
% create costpergallonsliderlabel
app.costpergallonsliderlabel = uilabel(app.leftpanel);
app.costpergallonsliderlabel.horizontalalignment = 'right';
app.costpergallonsliderlabel.fontcolor = [1 0.4118 0.1608];
app.costpergallonsliderlabel.position = [5 39 83 22];
app.costpergallonsliderlabel.text = 'cost per gallon';
% create costpergallonslider
app.costpergallonslider = uislider(app.leftpanel);
app.costpergallonslider.limits = [2 7.5];
app.costpergallonslider.majorticks = [2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5];
app.costpergallonslider.valuechangedfcn = createcallbackfcn(app, @costpergallonslidervaluechanged, true);
app.costpergallonslider.fontcolor = [1 0.4118 0.1608];
app.costpergallonslider.position = [109 48 352 3];
app.costpergallonslider.value = 2;
% create trailerweighteditfieldlabel
app.trailerweighteditfieldlabel = uilabel(app.leftpanel);
app.trailerweighteditfieldlabel.horizontalalignment = 'right';
app.trailerweighteditfieldlabel.fontcolor = [0.6353 0.0784 0.1843];
app.trailerweighteditfieldlabel.position = [5 176 79 22];
app.trailerweighteditfieldlabel.text = 'trailer weight';
% create trailerweighteditfield
app.trailerweighteditfield = uieditfield(app.leftpanel, 'numeric');
app.trailerweighteditfield.limits = [0 12000];
app.trailerweighteditfield.valuedisplayformat = '%.0f';
app.trailerweighteditfield.valuechangedfcn = createcallbackfcn(app, @trailerweighteditfieldvaluechanged, true);
app.trailerweighteditfield.fontcolor = [0.6353 0.0784 0.1843];
app.trailerweighteditfield.position = [99 176 100 22];
% create tripinmileseditfieldlabel
app.tripinmileseditfieldlabel = uilabel(app.leftpanel);
app.tripinmileseditfieldlabel.horizontalalignment = 'right';
app.tripinmileseditfieldlabel.fontcolor = [0 0.4471 0.7412];
app.tripinmileseditfieldlabel.position = [268 176 69 22];
app.tripinmileseditfieldlabel.text = 'trip in miles';
% create tripinmileseditfield
app.tripinmileseditfield = uieditfield(app.leftpanel, 'numeric');
app.tripinmileseditfield.valuechangedfcn = createcallbackfcn(app, @tripinmileseditfieldvaluechanged, true);
app.tripinmileseditfield.fontcolor = [0 0.4471 0.7412];
app.tripinmileseditfield.position = [352 176 100 22];
% create fueltypebuttongroup
app.fueltypebuttongroup = uibuttongroup(app.leftpanel);
app.fueltypebuttongroup.selectionchangedfcn = createcallbackfcn(app, @fueltypebuttongroupselectionchanged, true);
app.fueltypebuttongroup.title = 'fuel type';
app.fueltypebuttongroup.backgroundcolor = [1 0 0];
app.fueltypebuttongroup.position = [40 405 123 76];
% create gasolinebutton
app.gasolinebutton = uiradiobutton(app.fueltypebuttongroup);
app.gasolinebutton.text = 'gasoline';
app.gasolinebutton.position = [11 30 69 22];
app.gasolinebutton.value = true;
% create dieselbutton
app.dieselbutton = uiradiobutton(app.fueltypebuttongroup);
app.dieselbutton.text = 'diesel';
app.dieselbutton.position = [11 8 65 22];
% create trailertowedbuttongroup
app.trailertowedbuttongroup = uibuttongroup(app.leftpanel);
app.trailertowedbuttongroup.selectionchangedfcn = createcallbackfcn(app, @trailertowedbuttongroupselectionchanged, true);
app.trailertowedbuttongroup.title = 'trailer towed';
app.trailertowedbuttongroup.backgroundcolor = [1 1 0];
app.trailertowedbuttongroup.position = [285 405 123 76];
% create yesbutton
app.yesbutton = uiradiobutton(app.trailertowedbuttongroup);
app.yesbutton.text = 'yes';
app.yesbutton.position = [11 30 58 22];
app.yesbutton.value = true;
% create nobutton
app.nobutton = uiradiobutton(app.trailertowedbuttongroup);
app.nobutton.text = 'no';
app.nobutton.position = [11 8 65 22];
% create numberofenginecylindersbuttongroup
app.numberofenginecylindersbuttongroup = uibuttongroup(app.leftpanel);
app.numberofenginecylindersbuttongroup.selectionchangedfcn = createcallbackfcn(app, @numberofenginecylindersbuttongroupselectionchanged, true);
app.numberofenginecylindersbuttongroup.title = 'number of engine cylinders';
app.numberofenginecylindersbuttongroup.backgroundcolor = [0.6353 0.0784 0.1843];
app.numberofenginecylindersbuttongroup.position = [143 248 167 106];
% create button_4
app.button_4 = uiradiobutton(app.numberofenginecylindersbuttongroup);
app.button_4.text = '4';
app.button_4.position = [11 60 58 22];
app.button_4.value = true;
% create button_6
app.button_6 = uiradiobutton(app.numberofenginecylindersbuttongroup);
app.button_6.text = '6';
app.button_6.position = [11 38 65 22];
% create button_8
app.button_8 = uiradiobutton(app.numberofenginecylindersbuttongroup);
app.button_8.text = '8';
app.button_8.position = [11 16 65 22];
% create editfield
app.editfield = uieditfield(app.leftpanel, 'numeric');
app.editfield.position = [186 72 167 22];
% create centerpanel
app.centerpanel = uipanel(app.gridlayout);
app.centerpanel.layout.row = 1;
app.centerpanel.layout.column = 2;
% create calculatebutton
app.calculatebutton = uibutton(app.centerpanel, 'push');
app.calculatebutton.buttonpushedfcn = createcallbackfcn(app, @calculatebuttonpushed, true);
app.calculatebutton.backgroundcolor = [1 0.0745 0.651];
app.calculatebutton.position = [8 383 100 23];
app.calculatebutton.text = 'calculate';
% create plotbutton
app.plotbutton = uibutton(app.centerpanel, 'push');
app.plotbutton.position = [8 136 100 23];
app.plotbutton.text = 'plot';
% create rightpanel
app.rightpanel = uipanel(app.gridlayout);
app.rightpanel.layout.row = 1;
app.rightpanel.layout.column = 3;
% create uiaxes
app.uiaxes = uiaxes(app.rightpanel);
title(app.uiaxes, 'mpg vs. cost per mile')
xlabel(app.uiaxes, 'x')
ylabel(app.uiaxes, 'y')
zlabel(app.uiaxes, 'z')
app.uiaxes.position = [6 54 316 195];
% create milesgalloneditfieldlabel
app.milesgalloneditfieldlabel = uilabel(app.rightpanel);
app.milesgalloneditfieldlabel.backgroundcolor = [0 0 1];
app.milesgalloneditfieldlabel.horizontalalignment = 'right';
app.milesgalloneditfieldlabel.position = [96 468 74 22];
app.milesgalloneditfieldlabel.text = 'miles /gallon';
% create milesgalloneditfield
app.milesgalloneditfield = uieditfield(app.rightpanel, 'numeric');
app.milesgalloneditfield.valuechangedfcn = createcallbackfcn(app, @milesgalloneditfieldvaluechanged, true);
app.milesgalloneditfield.backgroundcolor = [0 0 1];
app.milesgalloneditfield.position = [185 468 100 22];
% create gallonsofusedfueleditfieldlabel
app.gallonsofusedfueleditfieldlabel = uilabel(app.rightpanel);
app.gallonsofusedfueleditfieldlabel.backgroundcolor = [1 0.4118 0.1608];
app.gallonsofusedfueleditfieldlabel.horizontalalignment = 'right';
app.gallonsofusedfueleditfieldlabel.position = [96 413 111 22];
app.gallonsofusedfueleditfieldlabel.text = 'gallons of used fuel';
% create gallonsofusedfueleditfield
app.gallonsofusedfueleditfield = uieditfield(app.rightpanel, 'numeric');
app.gallonsofusedfueleditfield.valuechangedfcn = createcallbackfcn(app, @gallonsofusedfueleditfieldvaluechanged, true);
app.gallonsofusedfueleditfield.backgroundcolor = [1 0.4118 0.1608];
app.gallonsofusedfueleditfield.position = [222 413 100 22];
% create costtofuelupeditfieldlabel
app.costtofuelupeditfieldlabel = uilabel(app.rightpanel);
app.costtofuelupeditfieldlabel.backgroundcolor = [0 1 0];
app.costtofuelupeditfieldlabel.horizontalalignment = 'right';
app.costtofuelupeditfieldlabel.position = [96 362 82 22];
app.costtofuelupeditfieldlabel.text = 'cost to fuel up';
% create costtofuelupeditfield
app.costtofuelupeditfield = uieditfield(app.rightpanel, 'numeric');
app.costtofuelupeditfield.valuechangedfcn = createcallbackfcn(app, @costtofuelupeditfieldvaluechanged, true);
app.costtofuelupeditfield.backgroundcolor = [0 1 0];
app.costtofuelupeditfield.position = [193 362 100 22];
% create costmileeditfieldlabel
app.costmileeditfieldlabel = uilabel(app.rightpanel);
app.costmileeditfieldlabel.backgroundcolor = [0.4941 0.1843 0.5569];
app.costmileeditfieldlabel.horizontalalignment = 'right';
app.costmileeditfieldlabel.position = [96 307 52 22];
app.costmileeditfieldlabel.text = 'cost/mile';
% create costmileeditfield
app.costmileeditfield = uieditfield(app.rightpanel, 'numeric');
app.costmileeditfield.valuechangedfcn = createcallbackfcn(app, @costmileeditfieldvaluechanged, true);
app.costmileeditfield.backgroundcolor = [0.4941 0.1843 0.5569];
app.costmileeditfield.position = [163 307 100 22];
% show the figure after all components are created
app.uifigure.visible = 'on';
end
end
% app creation and deletion
methods (access = public)
% construct app
function app = jonpagelsprojectgui
% create uifigure and components
createcomponents(app)
% register the app with app designer
registerapp(app, app.uifigure)
if nargout == 0
clear app
end
end
% code that executes before app deletion
function delete(app)
% delete uifigure when app is deleted
delete(app.uifigure)
end
end
end
jon
https://ww2.mathworks.cn/matlabcentral/profile/authors/30077047
tag:ww2.mathworks.cn,2005:question/1979844
2023-06-07t17:56:05z
2023-06-07t21:41:55z
bad optimization of an objective nonlinear fitting
i have a bad understanding why this optimization does not work. i have a raw signal which is the convolution between a signal x (which i would like to find by a fitting) and signal 2 which is known.
i need to optimize a convolution between a three-exponential terms function with signal sig2 (which is a response function that should not change, only the three-exponential fitting that shpould be optimized so that its convolution with sig2 should match the raw signal "sig1").
data = xlsread('rawdata.xlsx','sheet1','a2:c119000');
time = data(:,1) ;
sig1 = data(:,2) ;
sig2 = data(:,3) ;
% define signal 3 (three exponential terms fitting function)
modelfun = @(p,time) - 1.8785e-01*exp(-6e6 *time) - p(2)*exp(-p(3)*time) (1.8785e-01 p(2))*exp(-p(1)*time);
now i give very good starting points for the fitting
% define initial values for the parameters for the three-exponential terms
% fitting to be optimized
p0 = [1.4531e 03 3.5868e-01 1.9509e 05];
no i use lsqcurvefit to construct the final target function which should optimize the final fitting so that the convolution of the fitting with sig2 should reproduce well the raw data (sig1).
[params,resnorm,residual,exitflag,output,lambda,jacobian] = lsqcurvefit(@(p,time) conv(sig2,modelfun(p,time), 'same'),p0,time,sig1);
now if i display the output of this optimization (i display only the three-exponential term function):
tesfunc1 = - 1.8785e-01*exp(-6e6 *time) - params(2)*exp(-params(3)*time) (1.8785e-01 params(2))*exp(-params(1)*time);
figure
plot(time,sig1,'displayname' ,'raw signal' )
hold on
plot(time, tesfunc1, 'displayname' ,'optimized fitting')
xlabel('time');
ylabel('intensity');
legend
it is defenitely a bad optmization, if i do convolution with sig2, it does not reproduce theraw data at all:
objective = conv(sig2,tesfunc1);
figure
plot(time,sig1,'displayname' ,'raw signal' )
hold on
plot(time,objective(1:length(time))*(max(sig2)/max(objective)),'displayname' ,'objective function' ) % the max operation is only to scale as the convolution takes the total amplitude to a high level
xlabel('time');
ylabel('intensity');
legend
however, if i use exactly the initial parameters, it should be a very good fitting (apart fron the convolution changes the overall amplitude that i still do not know how to fix).:
tesfunc2 = - 1.8785e-01*exp(-6e6 *time) - p0(2)*exp(-p0(3)*time) (1.8785e-01 p0(2))*exp(-p0(1)*time);
% objective function if the optimization found parameters like in p0
% (declared initial points)
objective = conv(sig2,tesfunc2);
figure
plot(time,sig1,'displayname' ,'raw signal' )
hold on
plot(time,objective(1:length(time))*(max(sig2)/max(objective))*1.1,'displayname' ,'objective function' ) % again i do the rescaling manually
xlabel('time');
ylabel('intensity');
legend
of course for this testfunction i knew the parameters, and in reality i would like to find them. for the lsqcurvefit, even if i spoiled it with very good parameters giving the function above, it still missed the fitting completely!
i am wondering what can make this optimization better. and i have seen some use "fminunc" with a cost function that would be in my case (costfunction = @(params) mean((rawdata - conv(signal2, fittingfunction(:, params))).^2);)), but i do not really know how to implement it in my case.
many thanks in advance.
hamzachem
https://ww2.mathworks.cn/matlabcentral/profile/authors/25488595
tag:ww2.mathworks.cn,2005:question/1979879
2023-06-07t20:58:54z
2023-06-07t20:58:54z
create a matlab function that averages the input signal with the simulation running in the simulink -- no upload to workspace
i need to build a matlab function that is able to average the input signal over a specific time period.
in the signal below for example, i need the matlab function to calculate the average of the signal only in the time period from 0.05 to 0.07 s.
i cannot use the send to workspace feature (using to file or to workspace), i need to do this operation while the simulink model is running.
i cannot use this send-to-workspace feature as it will be implemented physically.
i'm a beginner and i don't know how to start
jefferson
https://ww2.mathworks.cn/matlabcentral/profile/authors/4481870
tag:ww2.mathworks.cn,2005:question/1979789
2023-06-07t16:05:06z
2023-06-07t20:22:04z
for the control subsystem of the four-switch buck-boost converter, may i know what are the functions of vref, v, ff, and reset?
hello,
i am a matlab beginner and i want to ask what are vref, v, ff, and reset, and their respective functions as part of the controller of the four-switch buck boost converter. attached is the simulik file of the circuit retrieved from https://www.mathworks.com/help/sps/ug/four-switch-buck-boost-converter-control.html. thank you!
mark ceasar cubelo
https://ww2.mathworks.cn/matlabcentral/profile/authors/22522286
tag:ww2.mathworks.cn,2005:question/1979869
2023-06-07t19:50:55z
2023-06-07t19:50:55z
previewing roi's on sequential .mat files (ir video data)
goal: display user defined roi's from the first image on subsequent images as a preview to ensure roi does not need to be adjusted before running the script on all images
i know there are multiple ways to do this, i thought the easiest would be to create a montage of every 10th or 20th frame and then apply this roi as perhaps a mask. i dont need to do any calculations in this roi, just make sure the object (worm) stays in the roi throughout the frames.
i have attached my coding: montage_v1 and v2 are different ways of doing the same thing, livewormroi's is where we set the roi (not my complete script but shows how roi's created and the ones i need to preview). the 12-14.mat file is an example image and the roi_details.png is a screenshot of the 5 roi's i need to preview on the movie/montage before running the script.
any help or advice would be greatly appreciated. i saw i can save the roi and apply it to each image but am trying to keep the processing time low and wasnt sure if that was the best way to do it.
thank you in advance for any assisstance!
kegan
https://ww2.mathworks.cn/matlabcentral/profile/authors/26779796
tag:ww2.mathworks.cn,2005:question/1979864
2023-06-07t19:50:05z
2023-06-07t19:50:05z
why can not output optimal solution when validate agent?
hello everyone,
topic: reinforcement learning, dqn agent.
i have trained an agent with my dataset (total 28 training data) then validated all these data. problem is i can not get optimal results at validation. some of them were good but not every result was good.
env: i custermized an environment.
i create critic with this function: critic = rlvectorqvaluefunction(nn,obsinfo,actinfo);
with critic create an dqn agent: agent = rldqnagent(critic);
i have tried new agent with only 1 data. training could get converged. validation gave also right answer to this data. but i trained an agent with all 28 data using the same hyperparameter. correctness is not garanteed.... i don't know what is reason. because of too small dataset? or i gave wrong hyperparameter?
hyperparameter of agent:
agent.agentoptions.epsilongreedyexploration.epsilondecay = 0.9;
agent.agentoptions.epsilongreedyexploration.epsilon = 0.9;
agent.agentoptions.epsilongreedyexploration.epsilonmin = 0.001;
agent.agentoptions.discountfactor = 0.99;
agent.agentoptions.minibatchsize = 128;
agent.agentoptions.criticoptimizeroptions.learnrate = 0.0008;
agent.agentoptions.criticoptimizeroptions.gradientthreshold = 1;
agent.agentoptions.saveexperiencebufferwithagent=true;
thank you
kun
kun cheng
https://ww2.mathworks.cn/matlabcentral/profile/authors/22825202
tag:ww2.mathworks.cn,2005:question/1979854
2023-06-07t19:37:12z
2023-06-07t19:37:12z
can i use academic version for my portfolio on github?
i wonder if it is forbidden for publishing my projects on github and my resume or it's ok with company terms.
mateusz
https://ww2.mathworks.cn/matlabcentral/profile/authors/27823705
tag:ww2.mathworks.cn,2005:question/595459
2020-09-17t14:54:59z
2023-06-07t18:55:14z
scattered interpolation: defining my own triangulation?
i'm interpolating data the comes from polar coordiate systems or terrain-following coordiante system used in numerical weather models. while that data isn't gridded in the since that it's not grid aligned, it is structured.
scattered interpolation is slow. my understanding is that this stems from computing the delaunay triangulation. for my data it would be trivial to provide the triangulation connectivity graph along with the points.
is there a way i can provide a pre computed triangulation to scatteredinterpolant or griddata in order to speed up my scattered interpolations? is there some hidden class property i could fill in somewhere?
millercommamatt
https://ww2.mathworks.cn/matlabcentral/profile/authors/1149557
tag:ww2.mathworks.cn,2005:question/1979759
2023-06-07t14:54:27z
2023-06-07t17:33:18z
is it possible to improve the solution process of an milp?
hello everybody,
i trying to optimize an charging station for evs, which is connected to a pv-modul, to an system storage systeme and to the network grid. i had no issues to simulate a month with time resolution of 15 minutes (pv and load data). however, when i try to simulate for a whole year. i obtain a solution only after 4310 seconds. moreover i am simulating for different battery capacities. so for each battery capacity i get the optimal solution only afeter more than one hour. here is my code and i tried to modify the options. can someone help me?
clearallmemoizedcaches;
clc;
clear;
clear vars;
load('lithium.mat');
k = input('k =');
if k == 1
a=flywheel;
elseif k == 2
a=lead;
elseif k == 3
a=lithium;
end
for i=0:5 %initialization of battery size
load('pv_data_year_15.mat');
load('demand_year_15.mat');
%% technical informations:
initial_aging_pv = 1;
n_station = 12;
kwp = 50; % peak power of pv-module
p_pv_standard = timetable2table(pv_data_year_15_clean);
p_pv_standard = table2array(p_pv_standard(:,4));
p_pv = p_pv_standard/10 * kwp;
p_pv = round(p_pv,3);
clear p_pv_standard;
capacity_batt = 0.5*i*kwp;
initial_batt= 0.4*capacity_batt;
p_batt_conv = capacity_batt; %max kw of batterie converter
p_load_time = timetable2table(demand_year_15_clean);
p_load_time = table2array(p_load_time(:,4))*4;
p_load = round(p_load_time,3);
clear p_load_time;
p_grid = max(p_load) 550;
capa_batt = zeros(numel(p_pv),1) capacity_batt;
usage_time_pv = 20; %year
usage_time_charger = 10; %year
loss_age = 0.2; %percent
loss_age_batt = 0.4; %percent, assumption that eol (80% remaining battery capacity) is after 15 years
delta_t = 0.25; % per 15 minutes
% costs parameters
cost_buy = zeros(numel(p_pv),1) 0.32; %euro/kwh
cost_customer = zeros(numel(p_pv),1);
%cost_pv = zeros(numel(p_pv),1);
cost_sell = zeros(numel(cost_buy),1) 0.078; %euro/kwh
cost_grid = 150; %euro/kw
cost_peak = 19.83; %euro/kw
c_pv = kwp * 1200; %euro
c_batt = capacity_batt * a.invest_costs_energy; %euro
%c_grid = p_grid * 600; %euro
c_station = n_station * 35000; %euro
cost_charger = 15000; %euro/kwh
%cost_batt_replace = zeros(numel(p_pv),1) 0.6 * c_batt * capacity_batt;
r = 0.05; %prozent
% efficiency:
eff_pv = 0.95;
eff_ch = sqrt(a.efficiency);
eff_dch = sqrt(a.efficiency);
eff_load = 0.9;
eff_grid = 0.95;
perc_aging_value = loss_age / (usage_time_pv*365*24) * delta_t;
ann_pv = ((1 r)^usage_time_pv * r)/((1 r)^usage_time_pv-1);
ann_batt = ((1 r)^a.usage_time * r)/((1 r)^a.usage_time-1);
ann_charger = ((1 r)^usage_time_charger * r)/((1 r)^usage_time_charger-1);
%% variables
costs = optimvar('costs',1); %euro
r_ch = optimvar('r_ch',1); %euro
c_buy = optimvar('c_buy',1); %euro
r_sell = optimvar('r_sell',1); %euro
c_peak = optimvar('c_peak',1); %euro
c_grid = optimvar('c_grid',1); %euro
p_buy = optimvar('p_buy', numel(p_pv),'lowerbound',0); %kw
p_sell = optimvar('p_sell', numel(p_pv),'lowerbound',0); %kw
p_peak = optimvar('p_peak',1,'lowerbound',0); %kw
i_buy = optimvar('i_buy',numel(p_pv),'type','integer'); %boolean
i_sell = optimvar('i_sell',numel(p_pv),'type','integer'); %boolean
%leistung
e_batt = optimvar('e_batt',numel(p_pv),'lowerbound',0); %kwh
p_ch = optimvar('p_ch',numel(p_pv),'lowerbound',0); %kw
p_dch = optimvar('p_dch',numel(p_pv),'lowerbound',0); %kw
p_charger = optimvar('p_charger',1,'lowerbound',0); %kw
i_ch = optimvar('i_ch',numel(p_pv),'type','integer'); %boolean
i_dch = optimvar('i_dch',numel(p_pv),'type','integer'); %boolean
%p_pv_var = optimvar('p_pv_var',numel(p_pv)); %kw
%% batterie charge/discharge
t_help1 = 1:1:numel(p_pv)-1;
t_help2 = 2:1:numel(p_pv);
e_batt_balance = optimconstr(numel(p_pv),1);
e_batt_balance(1) = e_batt(1) == initial_batt;
e_batt_balance(t_help2) = e_batt(t_help2) == e_batt(t_help1) p_ch(t_help1)*delta_t - p_dch(t_help1)*delta_t - (a.self_discharge/100) *capacity_batt;
%% optimization
prob = optimproblem();
prob.objective = costs; %min costs
%kostenaufstellung
prob.constraints.kosten1 = costs == - r_ch c_buy - r_sell c_bat_var c_grid c_peak;
prob.constraints.kosten2 = r_ch == cost_customer' * (p_load * delta_t);
prob.constraints.kosten3 = c_buy == cost_buy' * (p_buy * delta_t) ;
prob.constraints.kosten4 = r_sell == cost_sell' * (p_sell * delta_t);
prob.constraints.kosten5 = c_peak == cost_peak * p_peak;
prob.constraints.kosten6 = c_grid == p_peak * cost_grid * ann_charger;
prob.constraints.kosten7 = c_bat_var == cost_battery_var' * (p_dch*delta_t);
%prob.constraints.kosten8 = c_batt == capacity_batt * a.invest_costs_energy/(a.usage_time*12);
%prob.constraints.kosten6 = c_batt == age_batt_var' * cost_batt_replace;
%prob.constraints.kosten6 = c_charger == p_peak * cost_charger;
%energie balance
prob.constraints.leistung1 = p_sell/eff_grid - eff_grid * p_buy == eff_pv * p_pv - p_load / eff_load eff_dch * p_dch - p_ch / eff_ch; %energieerhaltungsgleichung
prob.constraints.leistung2 = p_buy >= 0;
prob.constraints.leistung3 = p_sell >= 0;
prob.constraints.leistung4 = i_buy i_sell <= 1; %buy or sell
prob.constraints.leistung5 = p_buy <= p_grid * i_buy ;
prob.constraints.leistung6 = p_sell <= p_grid * i_sell ;
prob.constraints.leistung7 = p_buy <= p_peak ;
prob.constraints.leistung8 = p_peak <= p_grid;
%prob.constraints.leistung9 = p_charger <= p_charger;
%prob.constraints.leistung9 = p_pv_var <= p_pv;
�tterierb
prob.constraints.batterie1 = e_batt_balance;
prob.constraints.batterie2 = i_ch i_dch <= 1; %charge or discharge
prob.constraints.batterie3 = p_ch >= 0;
prob.constraints.batterie4 = p_ch <= i_ch * p_batt_conv;
prob.constraints.batterie5 = p_dch >= 0;
prob.constraints.batterie6 = p_dch <= i_dch * p_batt_conv;
prob.constraints.batterie7 = e_batt >= 0.1 * capa_batt; %
prob.constraints.batterie8 = e_batt <= 0.9 * capa_batt; %
prob.constraints.batterie9 = p_dch <= a.ptoe_ratio*e_batt;
%zustaende
prob.constraints.zustand1 = i_sell i_dch <= 1;
prob.constraints.zustand2 = i_buy i_ch <= 1;
%% ausgabe
options = optimoptions('intlinprog','cutgeneration','advanced' ,'integerpreprocess','advanced','heuristicsmaxnodes',100,'heuristics','advanced','relativegaptolerance',5e-1); %,'rootlpalgorithm','primal-simplex','heuristicsmaxnodes',100,'heuristics','advanced'); % %'integerpreprocess','advanced');
tic
[sol,fval,exitflag] = solve(prob,'options',options);
toc % tic and toc used to profile code and identify performace bottlenecks
%% batteriestand an neuen tag übergeben
rev_sum = - sum(sol.costs) - ann_pv * c_pv - ann_batt * c_batt - ann_charger * c_station;
if exitflag == 1
if k == 1
ergebnis_leistung_flywheel = table(sol.p_buy,sol.p_sell,sol.p_ch,sol.p_dch,sol.e_batt,'variablenames',{'p_buy','p_sell','p_ch','p_dch','e_batt'});
save (['ergebnisse_leistung_flywheel',num2str(capacity_batt) 'kwh' '.mat'],'ergebnis_leistung_flywheel');
ergebnis_kosten_flywheel = table(sol.costs,sol.c_buy,sol.r_sell,sol.r_ch,sol.c_peak,sol.p_peak,sol.c_bat_var,'variablenames',{'costs','c_buy','r_sell','r_ch','c_peak','p_peak','c_bat_var'});
save (['ergebnisse_kosten_flywheel', num2str(capacity_batt) 'kwh' '.mat' ],'ergebnis_kosten_flywheel');
%save (['rev_sum_flyhwheel',num2str(capacity_batt) 'kwh' '.mat'],'rev_sum');
elseif k == 2
ergebnis_leistung_lead = table(sol.p_buy,sol.p_sell,sol.p_ch,sol.p_dch,sol.e_batt,'variablenames',{'p_buy','p_sell','p_ch','p_dch','e_batt'});
save (['ergebnisse_leistung_lead', num2str(capacity_batt) 'kwh' '.mat'],'ergebnis_leistung_lead');
ergebnis_kosten_lead = table(sol.costs,sol.c_buy,sol.r_sell,sol.r_ch,sol.c_peak,sol.p_peak,sol.c_bat_var,'variablenames',{'costs','c_buy','r_sell','r_ch','c_peak','p_peak','c_bat_var'});
save (['ergebnisse_kosten_lead', num2str(capacity_batt) 'kwh' '.mat' ],'ergebnis_kosten_lead');
%save (['rev_sum_lead',num2str(capacity_batt) 'kwh' '.mat'],'rev_sum');
elseif k == 3
ergebnis_leistung_lithium = table(sol.p_buy,sol.p_sell,sol.p_ch,sol.p_dch,sol.e_batt,'variablenames',{'p_buy','p_sell','p_ch','p_dch','e_batt'});
%ergebnis_leistung_lithium_month = [ergebnis_leistung_lithium_month;ergebnis_leistung_lithium];
save (['ergebnisse_leistung_lithium_month',num2str(capacity_batt) 'kwh' '.mat'],'ergebnis_leistung_lithium');
ergebnis_kosten_lithium = table(sol.costs,sol.c_buy,sol.r_sell,sol.r_ch,sol.c_bat_var,'variablenames',{'costs','c_buy','r_sell','r_ch','c_bat_var'});
%ergebnis_kosten_lithium_month = [ergebnis_kosten_lithium_month;ergebnis_kosten_lithium];
save (['ergebnisse_kosten_lithium_month',num2str(capacity_batt) 'kwh' '.mat' ],'ergebnis_kosten_lithium');
save (['rev_sum_lithium',num2str(capacity_batt) 'kwh' '.mat'],'rev_sum');
end
end
%end
end
mehdi zerzeri
https://ww2.mathworks.cn/matlabcentral/profile/authors/7281391
tag:ww2.mathworks.cn,2005:question/1979829
2023-06-07t17:26:34z
2023-06-07t17:27:54z
change coordinate system of geotif from wgs 34 to epsg:32628
hello
i have a geotif with data projected in wgs 84 (standart) and i want to convert it in epsg:32628
since .tif files cannot be uploaded here, i saved it in a .mat (using geotiffread and save). thus the data are in the file test.mat (attached). i want to read this data and export it in a new geotif but with different coordinate system, but i can't :
load test.mat
coordrefsyscode = 32628
geotiffwrite('test',a,r,'coordrefsyscode',coordrefsyscode)
i get this error :
error using geotiffwrite
function geotiffwrite expected input number 3, r, to be either a 3-by-2 referencing matrix or a scalar map
raster reference object. instead its type was: map.rasterref.geographiccellsreference.
how can i do it ?
timbro
https://ww2.mathworks.cn/matlabcentral/profile/authors/9671215
tag:ww2.mathworks.cn,2005:question/1979694
2023-06-07t13:44:30z
2023-06-07t17:23:29z
how to us arguments validation functions for multi-frame images
hi,
i am designing a function to analyse an image sequence frame by frame to return a vector of time according to the cardiac cycle. for the image file argument validation, how do i customise a validation function for these two purposes:
1) ensure each sequence have a reasonable duration (number of frames, minimum 75 frames in total)
2) must be a 3d array
thanks in advance!
function peaktimes = detectcardiacphase(img, framerate)
arguments
img (:,:,:) {mustbenumeric}
framerate double {mustbepositive} = 15 �fault value of framerate is not specified
end
wei yow
https://ww2.mathworks.cn/matlabcentral/profile/authors/28152288
tag:ww2.mathworks.cn,2005:question/1979799
2023-06-07t16:15:16z
2023-06-07t16:15:16z
setting path for cad parts in simscape multibody
i am creating a simscape project to simulate a 3d model i created with autodesk inventor 2021 (build 250183000, 183). i succesfully exported the .xml and .step files using the simscape multibody link plugin (version 7.4). i am also able to create the simulink model using the command:
smimport('filename.xml')
to keep my folders more clean i would like to have the model files in a separate folder and have the file solid blocks in the simulink file point to it. after creating a model_data folder in which i put all the .step files and the .xml file, i run:
smimport('model_data\filename.xml')
the simulink model is created again succesfully. however, this time it does not work as expected. in fact, all the file solid blocks have their geometry\file name field pointing directly to the .step file instead of containing the relative path to it (i.e., the file name field is still 'file.step' instead of 'model_data\file.step'). therefore, the .step files are not found correctly and the simulation cannot start. how can i fix this?
gianpietro battocletti
https://ww2.mathworks.cn/matlabcentral/profile/authors/9026634
tag:ww2.mathworks.cn,2005:question/1979794
2023-06-07t16:14:12z
2023-06-07t16:14:12z
eeglab erp plugin error save permission denied
for the eeglab program running on matlab, i have an erplab plugin that will not run.
i have tried changing the write permissions through properties (windows) for the plugin folder and for the whole matlab directory. any idea what might be causing this or which groups need permissions for which directories / files?
aileen a.
https://ww2.mathworks.cn/matlabcentral/profile/authors/30345238
tag:ww2.mathworks.cn,2005:question/1979784
2023-06-07t15:43:24z
2023-06-07t15:43:24z
for the control subsystem of the four-switch buck-boost converter, may i know what are the functions of vref, v, ff, and reset?
hello,
i am a matlab beginner and i want to ask what are vref, v, ff, and reset, and their respective functions as part of the controller of the four-switch buck boost converter. attached is the simulik file of the circuit retrieved from https://www.mathworks.com/help/sps/ug/four-switch-buck-boost-converter-control.html. thank you!
mark ceasar cubelo
https://ww2.mathworks.cn/matlabcentral/profile/authors/22522286
tag:ww2.mathworks.cn,2005:question/1979709
2023-06-07t13:50:13z
2023-06-07t15:33:38z
logic statements in function handle
i am trying to perform a logic statement in a function handle, so that i can evaluate a function at a series of coordinates, then make decisions.
i have the following:
p --> an n x 2 double array. contains pairs of coordinates [x,y]
fi --> a griddedinterpolant function. the coordinates in p fall within range and domain of the grid that was interpolated to obtain this (so they are compatible).
fi2 --> a second griddedinterpolant function, derived from a second set of data more or less the same as in fi.
important point: the values that can be evaluated in fi and fi2 are partially mutually exclusive. if fi is negative, the fi2 must be positive, and the other way around. however, it is possible for both to be positive (there is a gap between them).
i've used this to make a function handles as follow:
fd=@(p) fi(p);
fd2=@(p) fi2(p);
these work just fine for calling later on and give nice sensible values when evaluated at p or sub-arrays of p.
here's the tricky bit. i want to make a new function handle ("fh") that takes the evaluations of these functions at p, and then makes a step-change based on certain results for each individial p entry. essentially, i want a function handle that does the work of an if statement. so, i tried to accomplish this by making 2 function handles for evaluating, and then treating them as logic statements, so i am multiplying by 1 or 0.
what i have tried (simplified), is this:
fha=@(p) (feval(fd,p));
fhb=@(p) (feval(fd2,p));
fh=@(p) max((fha<(0))*a, (fhb)<(0)*b, ((fha)>(0)*(fhb)>(0))*((a b)/2));
this should be the equivalent of:
if fha < 0, then a; elseif fhb < 0, then b; else average of a and b
in other words, if a point within p has coordinates in a region where fd is negative, that point will have an associate value a. if it is in a position where fd2 is negative, it will be b. but if it falls in the regions where both evaluate to positive, its assigned value is the average of a and b.
i've also tried this nesting the feval statements into the fh call, and doing it as a single handle. neither has worked. is there a smart way to approach this, keeping in mind that i need to pass this handle to another function and then do lots of array manipulation stuff with it?
geoffrey rivers
https://ww2.mathworks.cn/matlabcentral/profile/authors/17875485
tag:ww2.mathworks.cn,2005:question/1979779
2023-06-07t15:18:39z
2023-06-07t15:18:39z
how to wait for another gui button press in appdesigner?
so, i have webapp with the following loose structure.
user clicks start in the gui
a sound is played
user clicks one of several buttons to rate the sound
the app waits for response
plays another sound shortly after recieving repsonse etc.
i'm stuck with trying to make the app wait for user response. i tried setting a while loop that would wait for a check variable to become true, and assigning that change in each button, but this didn't work, the buttons are not executable when it is in the while loop.
documentations suggests "use uiwait" but the ui wait documentation doesn't give any further clue how this would be done when relying on callbacks etc, only when closing like dialogue boxes etc.
if i use uiwait()&uiresume, then it creates a figure external to the app which cannot be disabled as far as i can tell.
thank you!
huw s
https://ww2.mathworks.cn/matlabcentral/profile/authors/8556464
tag:ww2.mathworks.cn,2005:question/1979769
2023-06-07t15:13:37z
2023-06-07t15:13:37z
how to read data from keithley voltmeter and hp signal analyzer using visa interface
i established the objects through the visa innterface, but after trying to write the data from it i am recieving the error
"read(hpfreqanalyzer, 6)
adaptor command 'setresourceattribute' failed with status code: -480."
i checked the connection by trying to re establish the object and am now recieving the error
>> currentmeter = visadev("gpib0::3::instr")
resource string is invalid or resource was not found.
see related documentation for troubleshooting steps.
even though the object is in my window on the right hand side.
andrew gamble
https://ww2.mathworks.cn/matlabcentral/profile/authors/5309133
tag:ww2.mathworks.cn,2005:question/1979764
2023-06-07t15:08:23z
2023-06-07t15:08:23z
adjustment of the pin-to-pin distance to create the maximum reach posture of the front of a hydraulic excavator. (adjustment of cylindrical joint and revolute joint)
i would like to reproduce the movement of the front part of a hydraulic excavator in simscape multibody.
i would like to fix the distance between the pins (cylinder length) in order to create the maximum reach posture of the front part, but i do not know how to do this.
currently, we are trying to adjust the limits of the cylindrical joint and the revolute joint to get the behavior closer to that of a real excavator, but we are not fully aware of the effect of the limits.
how can we fix the distance between the pins and create the maximum reach posture?
i would appreciate it if you could help me.
thank you in advance.
hidenobu kawae
https://ww2.mathworks.cn/matlabcentral/profile/authors/26187842
tag:ww2.mathworks.cn,2005:question/1956989
2023-05-03t01:58:09z
2023-06-07t14:56:37z
issues using simulink coder to generate veristand-compatible c code
i have installed the three required support packages to generate veristand compatible models: veristand model generation support, matlab support for mingw-w64 c/c compiler, and c/c development tools for ni linux real-time 2017. when i use simulink coder in r2020b or r2021a, the ports, parameters and signals readme files are missing in the rtw folder.
i installed 2019b since my colleague is able to generate a full set of files using that version, installed all the support packages but i cannot even complete the build. it terminates with this error:
the call to veristand_make_rtw_hook, during the before_make hook generated the following error: 'modelparameters' is not a valid datainterface type. the valid datainterface types are described by 'getalldatainterfacetypes' method on the codedescriptor object
the build process will terminate as a result.
caused by:
'modelparameters' is not a valid datainterface type. the valid datainterface types are described by 'getalldatainterfacetypes' method on the codedescriptor object
oddly enough, the coder in 2019b is able to succesfully the complete the build for a generic target. i'm not sure where the issue is coming from.
i would appreciate a solution for either of these issues but i would prefer to be able to generate the necessary ports and parameters text files using r2020b.
ishita ray
https://ww2.mathworks.cn/matlabcentral/profile/authors/7248066
tag:ww2.mathworks.cn,2005:question/1979749
2023-06-07t14:47:59z
2023-06-07t14:47:59z
i have an image and want to perform edge detection and highlight them
i have an edge detected image and would like to highlight the edges of triangle as as the edges are not straight and it has jugged lines (uneven line).
after detecting those edges and displaying them, i also have to calculate the length of the edges of each triangle in the given image and display those triangles along with the length of each edges.
i have attached the image for reference and also the image on how the highlighted image (output) should look like.
i tried the code but all the sides are not getting highlighted.
clc;
close all;
clear all;
% perform edge detection
edgedimage = imread('smooth_imgprocessed_in_matlabcode.jpg');
% convert the image to grayscale if necessary
if size(edgedimage, 3) == 3
edgedimage = rgb2gray(edgedimage);
end
% detect edges using canny edge detection
edges = edge(edgedimage, 'canny');
% perform hough transform to detect straight lines
[h,theta,rho] = hough(edges);
peaks = houghpeaks(h, 10); % adjust the number of peaks to detect more or fewer lines
% find lines using hough transform peaks
lines = houghlines(edges,theta,rho,peaks);
% initialize cell array to store triangular edges
triangularedges = cell(0);
% iterate through the detected lines and find triangular edges
for i = 1:length(lines)
for j = i 1:length(lines)
anglediff = abs(lines(i).theta - lines(j).theta);
if anglediff > 80 && anglediff < 100 % adjust the angle difference threshold as needed
% store the triangular edges in the cell array
triangularedges{end 1} = [lines(i) lines(j)];
end
end
end
% display the original edged image
figure;
imshow(edgedimage);
hold on;
% highlight triangular edges in red color
for k = 1:length(triangularedges)
edges = triangularedges{k};
for m = 1:size(edges, 2)
x = [edges(m).point1(1), edges(m).point2(1)];
y = [edges(m).point1(2), edges(m).point2(2)];
plot(x, y, 'linewidth', 2, 'color', 'r');
end
end
hold off;
surabhi a s
https://ww2.mathworks.cn/matlabcentral/profile/authors/26033270
tag:ww2.mathworks.cn,2005:question/1975304
2023-05-29t21:00:40z
2023-06-07t14:31:21z
changing initial conditions of a simulink model when simulating using a for loop
i am trying to run a vehicle simulink model (taken from here) for 5 seconds. when i try running it directly, the response seems to make sense.
however, when i use a for loop to do the same using a for loop (see attached runexample.m), the response is quite different. my assumption is i am not changing the initial conditions after each loop properly. is there a way to update the initial conditions automatically instead of the way i am doing it, i.e., manually? what other ways could i trye to have the same responses with and without the for loop?
all the relevant files are uploaded. simply set rundirect in the runexample.m file to true to run without the for loop, otherwise, set it to false.
thanks in advance for your time. looking forward to get some solution.
j ai
https://ww2.mathworks.cn/matlabcentral/profile/authors/15095724
tag:ww2.mathworks.cn,2005:question/1978364
2023-06-05t09:02:34z
2023-06-07t14:15:17z
cycle basis for large graph
i have a graph of around 3 million nodes and 10 million edges.
i want to get the cycle basis of the graph but it runs out of memory when using the command cyclebasis(g).
is there a way to solve it?
tala dannawi
https://ww2.mathworks.cn/matlabcentral/profile/authors/12025618
tag:ww2.mathworks.cn,2005:question/1979729
2023-06-07t14:09:18z
2023-06-07t14:09:18z
how can i fix these er index exceeds array bounds. error in ext2int (line 163) bs(n2i(mpc.branch(:, t_bus))) ); error in power_flow_case (line 44) mpc = ext2int(mpc, mpopt);
function mpc = power_flow_case()
% bus data
mpc.bus = [
1 3 0 0 0 0 1.060 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
2 2 0 0 0 0 1.045 0 0 230 13.2 300 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
3 2 0 0 0 0 1.010 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
4 1 0 0 0 0 1.070 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
5 1 0 0 0 0 1.090 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
6 1 0 0 0 0 1.090 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
7 1 0 0 0 0 1.060 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
8 2 0 0 0 0 1.035 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
];
% generator data
mpc.gen = [
1 0 0 100 -100 1.05 300 1 300 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
% add more generator data if needed
];
% transformer data
mpc.branch = [
1 2 0 0.15 0.1 0 0 0 0 0 1 -360 360 0 1;
2 3 0 0.2 0.15 0 0 0 0 0 1 -360 360 0 1;
];
% line data
mpc.branch = [
mpc.branch;
2 4 0 0.00032*30 0.0024*30 0 0 0 0 0 1 -360 360 0 1;
5 6 0 0.00032*40 0.0024*40 0 0 0 0 0 1 -360 360 0 1;
6 7 0 0.00032*40 0.0024*40 0 0 0 0 0 1 -360 360 0 1;
7 8 0 0.00032*35 0.0024*35 0 0 0 0 0 1 -360 360 0 1;
2 9 0 0.00032*60 0.0024*60 0 0 0 0 0 1 -360 360 0 1;
];
% base quantities
mpc.basemva = 300;
mpc.bus(:,3) = mpc.bus(:,3) / mpc.basemva;
mpc.branch(:,4:6) = mpc.branch(:,4:6) * mpc.basemva;
mpc.gen(:,2:3) = mpc.gen(:,2:3) / mpc.basemva;
% run the power flow
mpopt = mpoption('pf.nr.max_it', 20);
mpc = ext2int(mpc, mpopt);
results = runpf(mpc, mpopt);
end
baris
https://ww2.mathworks.cn/matlabcentral/profile/authors/30334575
tag:ww2.mathworks.cn,2005:question/1979714
2023-06-07t14:04:49z
2023-06-07t14:04:49z
windows server 2022 matlab compiled app crashes every hour
i have a matlab app compiled in r2020b and executed on windows server 2022 where i have the runtime 9.9.
every hour, seems randomically, my app crashes and from the windows event viewer i get the following:
faulting application name: matlabwindow.exe, version: 9.9.0.0, time stamp: 0x4b3d3b00
faulting module name: ntdll.dll, version: 10.0.20348.681, time stamp: 0x69d3cd31
exception code: 0xc0000005
fault offset: 0x000000000001c99f
faulting process id: 0x1a80
faulting application start time: 0x01d996a021ecc232
faulting application path: c:\program files\matlab\matlab runtime\v99\bin\win64\matlabwindow.exe
faulting module path: c:\windows\system32\ntdll.dll
report id: d0bf55a1-54e6-4d42-a1fa-26eecf8f25e8
faulting package full name:
faulting package-relative application id:
how can i fix this issue?
marco fanton
https://ww2.mathworks.cn/matlabcentral/profile/authors/18894797
tag:ww2.mathworks.cn,2005:question/1979704
2023-06-07t13:48:52z
2023-06-07t13:48:52z
数据采集频次(frequency of data collection)
在开始数据采集时,请问数据采集频次是几秒一次呢?
(when starting data collection, how often is the data collection frequency in seconds?)
peppa zhao
https://ww2.mathworks.cn/matlabcentral/profile/authors/16302882
tag:ww2.mathworks.cn,2005:question/1979699
2023-06-07t13:46:39z
2023-06-07t13:46:39z
what does the following error mean "internal error while creating code interface description file: codeinfo.mat. aborting code generation."
codegen is throwing the following error when doing code generation
"internal error while creating code interface description file: codeinfo.mat. aborting code generation.
caused by:
index exceeds the number of array elements. index must not exceed 0. "
the error doesn't give any more information and hence cannot figure out what is the problem. using ert based target file.
harshin vora
https://ww2.mathworks.cn/matlabcentral/profile/authors/25509284
tag:ww2.mathworks.cn,2005:question/1979679
2023-06-07t13:10:52z
2023-06-07t13:15:16z
error when running simulink
i am having trouble running my system i am using the simscape battery package to design the system. when i run the code i am getting this error
error due to multiple causes.
caused by:
error evaluating parameter 'soc_veccell' in 'battery_system/pack1/moduleassembly1/module1'
unable to resolve the name 'moduletype1.soc_veccell'.
please leave suggestions. i have also attacthed the file below.
darragh
https://ww2.mathworks.cn/matlabcentral/profile/authors/30160486
tag:ww2.mathworks.cn,2005:question/1979669
2023-06-07t12:50:20z
2023-06-07t12:50:20z
how are the inductor and capacitor values of the boost converter calculated?
i have a grid connected photovoltaic system including pv panel, boost converter, single phase inverter and lc filter.
how can i calculate the inductor and capacitor values of the boost converter?
mohammad sh
https://ww2.mathworks.cn/matlabcentral/profile/authors/21129921
tag:ww2.mathworks.cn,2005:question/1979654
2023-06-07t12:19:12z
2023-06-07t12:46:45z
how to plot this circulair domaine ?
fouzi redouane
https://ww2.mathworks.cn/matlabcentral/profile/authors/20782602
tag:ww2.mathworks.cn,2005:question/1979664
2023-06-07t12:46:37z
2023-06-07t12:46:37z
simulink function block output not resolving to signal
i am trying to generate a signal driving a current source using a function block in simulink. but i am getting errors about the output ”iharm”. the function works fine in matlab workspace but not working in simulink environment.
error:
output 'iharm' has variable size but the upper bound is not specified; explicit upper bound must be provided.
or “iharm” can not resolve to signal object.
i have tried specifying the bounds using assert and coder.varsize, but still error is there. also specifying “data must resolve to signal object” in model workspace does not seem to work.
simulink model is attached if anyone can help me to resolve this issue.
haroon zafar
https://ww2.mathworks.cn/matlabcentral/profile/authors/22459364
tag:ww2.mathworks.cn,2005:question/1979659
2023-06-07t12:44:34z
2023-06-07t12:44:34z
并行计算使用parsim,每个循环中参数可以更改,工况怎么改(通过from workspace加载工况,时间和速度二维向量)
for i=1:100
in(i) = simulink.simulationinput(model);
end
out = parsim(in, 'showprogress', 'on','transferbaseworkspacevariables','on','usefastrestart','on');
先用for建立并行计算对象in;
在parsim并行计算过程中,每个循环的计算中,v_ms_front{i}加载的都是第100组数据。
这问题怎么解决?
硕 蔡
https://ww2.mathworks.cn/matlabcentral/profile/authors/20888325
tag:ww2.mathworks.cn,2005:question/1979564
2023-06-07t09:31:01z
2023-06-07t12:43:07z
caluclating an integral over a rectangle, with a singularity point.
hi! i am trying to evaluate the following integral:
where bx,by are some set values.
so i wrote the following code:
funcl_nn = @(x,z) (1/(4*pi*epsilon_zero))*(1./sqrt(x.^2 z.^2));
nn = quad2d(funcl_nn,-dist/2,dist/2,-bz/2,bz/2,'abstol',1e-8,'singular',true,maxfunevals=100000);
and also tried to use integral2 and tiled method, but it always returns: warning: reached the maximum number of function evaluations (100000). the result fails the global error test.
what's weird is that if i change the values of by,bx to be larger, then the error does not occur.
i assume it is caused by the point (0,0).
i would try to switch to polar coordinates if the domain wasn't rectangular... can anyone tell me what can i do such a situation? thanks in advance!
mickey
https://ww2.mathworks.cn/matlabcentral/profile/authors/27026524
tag:ww2.mathworks.cn,2005:question/1979649
2023-06-07t12:15:35z
2023-06-07t12:17:15z
error in trapz in matlab
i get an error "error in trapz (line 42)
perm = [dim:max(ndims(y),dim) 1:dim-1];" for the code
j = trapz(t, y(:, 2) y(:, 3) y(:, 4) y(:, 5) k/2*u.^2);
nezi
https://ww2.mathworks.cn/matlabcentral/profile/authors/30344094
tag:ww2.mathworks.cn,2005:question/1979639
2023-06-07t12:04:20z
2023-06-07t12:05:31z
input live data (continuously generated data) from app designer to simulink
hello,
i am trying to calculate state of charge using simulink block diagrams. my current and voltage adc values are gotten from a serial port and sent to app designer to get the actual current and voltage. i am trying to get this values to simulink.
i have tried using "assignin" to send the variables to the work space and then read them from there, but the variables are not updateing. the simulink model reads the first values and stops. after i stop the app, the work space then updates to the lates value.
i wish to ask how i can get this running with variables flowing from app designer to simulink and updating as required?
thanks
kizito amungwa achembong
https://ww2.mathworks.cn/matlabcentral/profile/authors/14024171