Category: Matlab
Category Archives: Matlab
how to pass parameters in arx function for MISO system identification
This is my code for an estimation of a MISO system:
na= 1;
nb1=1;
nb2=1;
sampleTime = 300; % seconds
inputNames = ["HCL_in", "NaHCO3"];
outputName = "HCL_out";
data = iddata(Dati1_timetable{:,outputName}, Dati1_timetable{:, inputNames}, sampleTime);
sys5 = arx(data, [na nb1 nb2])
and I have this error :
Error using arx (line 84)
the model orders must be compatible with the input an output dimensions of the estimation data.
if I substitute ONLY " inputNames = ["HCL_in", "NaHCO3"]; " with this: " inputNames = HCL_in; " , so from MISO to SISO system identification, all works fine.
Please help me, thanks.This is my code for an estimation of a MISO system:
na= 1;
nb1=1;
nb2=1;
sampleTime = 300; % seconds
inputNames = ["HCL_in", "NaHCO3"];
outputName = "HCL_out";
data = iddata(Dati1_timetable{:,outputName}, Dati1_timetable{:, inputNames}, sampleTime);
sys5 = arx(data, [na nb1 nb2])
and I have this error :
Error using arx (line 84)
the model orders must be compatible with the input an output dimensions of the estimation data.
if I substitute ONLY " inputNames = ["HCL_in", "NaHCO3"]; " with this: " inputNames = HCL_in; " , so from MISO to SISO system identification, all works fine.
Please help me, thanks. This is my code for an estimation of a MISO system:
na= 1;
nb1=1;
nb2=1;
sampleTime = 300; % seconds
inputNames = ["HCL_in", "NaHCO3"];
outputName = "HCL_out";
data = iddata(Dati1_timetable{:,outputName}, Dati1_timetable{:, inputNames}, sampleTime);
sys5 = arx(data, [na nb1 nb2])
and I have this error :
Error using arx (line 84)
the model orders must be compatible with the input an output dimensions of the estimation data.
if I substitute ONLY " inputNames = ["HCL_in", "NaHCO3"]; " with this: " inputNames = HCL_in; " , so from MISO to SISO system identification, all works fine.
Please help me, thanks. arx, miso, syste identification MATLAB Answers — New Questions
Parallel pool never releases used memory leading to instability
Running code like:
rxs = rxsite("AntennaHeight",1.5, …
"Latitude", 38.9899587, "Longitude", -76.9353889);
for scenario = 1:2
switch scenario
% these are not meaningful paths
case 1
txPositions = [linspace(38.9857294, 38.9857294, 10000).’, linspace(-76.9442905, -76.9407240, 10000).’];
case 2
txPositions = [linspace(38.9895908, 38.9903186, 10000).’, linspace(-76.9432997, -76.9446669, 10000).’];
end
pm = propagationModel("raytracing");
data = [];
parfor point = 1:size(txPositions,1)
txs = txsite("AntennaHeight", 1.5, …
"Latitude", txPositions(1,point), "Longitude", txPositions(2,point), …
"TransmitterPower", 10);
rays = raytrace(txs, rxs, pm, "type", "power"); % rays is Na x Ns cell array
if ~isempty(rays{1}) % only ever 1 tx/1 rx
rayPower = 0;
% phasor sum of rec’d power
for rayPath = 1:numel(rays{1})
pWatts = 10^(-rays{1}(rayPath).PathLoss/10)*10;
rayPower = rayPower + pWatts*(cos(rays{1}(rayPath).PhaseShift) + 1i*sin(rays{1}(rayPath).PhaseShift));
end
% convert to RSS in dBm and resultant signal phase offset
RSS = 10*log10(abs(rayPower)/.001); % dBm
phaseOffset = angle(rayPower) ; % rads
% collate data
data = [samplePoints(step, 1), samplePoints(step, 2), RSS, phaseOffset];
end
end
close all force % this is an attempt to fix this issue
save("data.mat","data")
clear data
delete(gcp)
end
This code will spawn a transmitter, move it along a path, sample the RSS at a receiver then append that data into a list which gets saved. After that, the parallel pool is reinitialized and the data variable is cleared before starting the next scenario. The delete(gcp) line was from another about a similar issue which I cant find anymore – this helps but doens’t solve the problem.
Running this code, I would expect the memory usage to increase during a single scenario (which is what I see), but I would also expect to see memory usage drop considerably between scenarios. However, this code causes the memory usage to steadily increase across scenarios, regardless of if I delete the parallel pool and clear variables. This almost always results in MATLAB either locking up the computer or just crashing outright.
The issue never occurs on the first (or even the first few) scenario, but will always happen after some number have been run, so I know that the individual scenarios are totally fine.
Am I going about this wrong or is there something I should do to fix this? This issue is present on R2024b on Ubuntu22 and Win10.Running code like:
rxs = rxsite("AntennaHeight",1.5, …
"Latitude", 38.9899587, "Longitude", -76.9353889);
for scenario = 1:2
switch scenario
% these are not meaningful paths
case 1
txPositions = [linspace(38.9857294, 38.9857294, 10000).’, linspace(-76.9442905, -76.9407240, 10000).’];
case 2
txPositions = [linspace(38.9895908, 38.9903186, 10000).’, linspace(-76.9432997, -76.9446669, 10000).’];
end
pm = propagationModel("raytracing");
data = [];
parfor point = 1:size(txPositions,1)
txs = txsite("AntennaHeight", 1.5, …
"Latitude", txPositions(1,point), "Longitude", txPositions(2,point), …
"TransmitterPower", 10);
rays = raytrace(txs, rxs, pm, "type", "power"); % rays is Na x Ns cell array
if ~isempty(rays{1}) % only ever 1 tx/1 rx
rayPower = 0;
% phasor sum of rec’d power
for rayPath = 1:numel(rays{1})
pWatts = 10^(-rays{1}(rayPath).PathLoss/10)*10;
rayPower = rayPower + pWatts*(cos(rays{1}(rayPath).PhaseShift) + 1i*sin(rays{1}(rayPath).PhaseShift));
end
% convert to RSS in dBm and resultant signal phase offset
RSS = 10*log10(abs(rayPower)/.001); % dBm
phaseOffset = angle(rayPower) ; % rads
% collate data
data = [samplePoints(step, 1), samplePoints(step, 2), RSS, phaseOffset];
end
end
close all force % this is an attempt to fix this issue
save("data.mat","data")
clear data
delete(gcp)
end
This code will spawn a transmitter, move it along a path, sample the RSS at a receiver then append that data into a list which gets saved. After that, the parallel pool is reinitialized and the data variable is cleared before starting the next scenario. The delete(gcp) line was from another about a similar issue which I cant find anymore – this helps but doens’t solve the problem.
Running this code, I would expect the memory usage to increase during a single scenario (which is what I see), but I would also expect to see memory usage drop considerably between scenarios. However, this code causes the memory usage to steadily increase across scenarios, regardless of if I delete the parallel pool and clear variables. This almost always results in MATLAB either locking up the computer or just crashing outright.
The issue never occurs on the first (or even the first few) scenario, but will always happen after some number have been run, so I know that the individual scenarios are totally fine.
Am I going about this wrong or is there something I should do to fix this? This issue is present on R2024b on Ubuntu22 and Win10. Running code like:
rxs = rxsite("AntennaHeight",1.5, …
"Latitude", 38.9899587, "Longitude", -76.9353889);
for scenario = 1:2
switch scenario
% these are not meaningful paths
case 1
txPositions = [linspace(38.9857294, 38.9857294, 10000).’, linspace(-76.9442905, -76.9407240, 10000).’];
case 2
txPositions = [linspace(38.9895908, 38.9903186, 10000).’, linspace(-76.9432997, -76.9446669, 10000).’];
end
pm = propagationModel("raytracing");
data = [];
parfor point = 1:size(txPositions,1)
txs = txsite("AntennaHeight", 1.5, …
"Latitude", txPositions(1,point), "Longitude", txPositions(2,point), …
"TransmitterPower", 10);
rays = raytrace(txs, rxs, pm, "type", "power"); % rays is Na x Ns cell array
if ~isempty(rays{1}) % only ever 1 tx/1 rx
rayPower = 0;
% phasor sum of rec’d power
for rayPath = 1:numel(rays{1})
pWatts = 10^(-rays{1}(rayPath).PathLoss/10)*10;
rayPower = rayPower + pWatts*(cos(rays{1}(rayPath).PhaseShift) + 1i*sin(rays{1}(rayPath).PhaseShift));
end
% convert to RSS in dBm and resultant signal phase offset
RSS = 10*log10(abs(rayPower)/.001); % dBm
phaseOffset = angle(rayPower) ; % rads
% collate data
data = [samplePoints(step, 1), samplePoints(step, 2), RSS, phaseOffset];
end
end
close all force % this is an attempt to fix this issue
save("data.mat","data")
clear data
delete(gcp)
end
This code will spawn a transmitter, move it along a path, sample the RSS at a receiver then append that data into a list which gets saved. After that, the parallel pool is reinitialized and the data variable is cleared before starting the next scenario. The delete(gcp) line was from another about a similar issue which I cant find anymore – this helps but doens’t solve the problem.
Running this code, I would expect the memory usage to increase during a single scenario (which is what I see), but I would also expect to see memory usage drop considerably between scenarios. However, this code causes the memory usage to steadily increase across scenarios, regardless of if I delete the parallel pool and clear variables. This almost always results in MATLAB either locking up the computer or just crashing outright.
The issue never occurs on the first (or even the first few) scenario, but will always happen after some number have been run, so I know that the individual scenarios are totally fine.
Am I going about this wrong or is there something I should do to fix this? This issue is present on R2024b on Ubuntu22 and Win10. parallel computing MATLAB Answers — New Questions
Integration of MATLAB/Simulink DLL into DIgSILENT PowerFactory
Dear Sir or Madam,
I am interested in create a dynamic model of a power converter in DIgSILENT PowerFactory which I already have modelled in MATLAB/Simulink. For that purpose I would like to use DLL files instead of model the converter from scratch.
Is there any tutorial/user manual/ in order to know how to properly export a DLL file from MATLAB/Simulink such that PowerFactory can read it correctly?
Thank you very much in advance.
Best regards,
VÍCTOR SÁNCHEZ SUÁREZDear Sir or Madam,
I am interested in create a dynamic model of a power converter in DIgSILENT PowerFactory which I already have modelled in MATLAB/Simulink. For that purpose I would like to use DLL files instead of model the converter from scratch.
Is there any tutorial/user manual/ in order to know how to properly export a DLL file from MATLAB/Simulink such that PowerFactory can read it correctly?
Thank you very much in advance.
Best regards,
VÍCTOR SÁNCHEZ SUÁREZ Dear Sir or Madam,
I am interested in create a dynamic model of a power converter in DIgSILENT PowerFactory which I already have modelled in MATLAB/Simulink. For that purpose I would like to use DLL files instead of model the converter from scratch.
Is there any tutorial/user manual/ in order to know how to properly export a DLL file from MATLAB/Simulink such that PowerFactory can read it correctly?
Thank you very much in advance.
Best regards,
VÍCTOR SÁNCHEZ SUÁREZ dll, powerfactory, dynamic model MATLAB Answers — New Questions
save() seems to be saving objects that should be destroyed, causing errors when the resulting .mat file is loaded
Example code:
txs = txsite("AntennaHeight",1.5, …
"Latitude", 38.9899587, "Longitude", -76.9353889, …
"TransmitterPower", 10);
txs = txsite("AntennaHeight", 1.5, …
"Latitude", 38.9860195, "Longitude", -76.9412203);
rays = raytrace(txs, rxs, pm, "type", "power"); % rays is Na x Ns cell array
if ~isempty(rays{1}) % only ever 1 tx/1 rx
rayPower = 0;
% phasor sum of rec’d power
for rayPath = 1:numel(rays{1})
pWatts = 10^(-rays{1}(rayPath).PathLoss/10)*10;
rayPower = rayPower + pWatts*(cos(rays{1}(rayPath).PhaseShift) + 1i*sin(rays{1}(rayPath).PhaseShift));
end
% convert to RSS in dBm and resultant signal phase offset
RSS = 10*log10(abs(rayPower)/.001); % dBm
phaseOffset = angle(rayPower) ; % rads
% collate data
data = [samplePoints(step, 1), samplePoints(step, 2), RSS, phaseOffset];
end
close all force % this is an attempt to fix this issue
save("data.mat","data")
The above code works as expected however, running:
load("data.mat")
Will result in the following warnings being spammed in the console:
> In <FUNCTION> (line 25)
Warning: Unable to load C++ object. Saving (serializing) C++ objects into a MAT-file is not supported.
> In <FUNCTION> (line 25)
Warning: Cannot load an object of class ‘proplistener’:
No matching constructor signature found.
> In <FUNCTION> (line 25)
Warning: During load:
An invalid default object has been detected while loading a heterogeneous array of class event.proplistener. An empty array of
class event.proplistener will be returned.
> In <FUNCTION> (line 25)
Warning: While loading an object of class ‘siteviewer’:
Unrecognized field name "Name".
I thought foriclby closing the siteviewer would work (or at least get rid of the last error), but it has not seemed to have an effect. What command should I run to fix this behavior?
Tested on 2023b, 2024b and the 2025 prerelease across two computers (one Win10, one Ubuntu22) which both had similar behaviors, although the Windows mahcine produced far fewer warnings.Example code:
txs = txsite("AntennaHeight",1.5, …
"Latitude", 38.9899587, "Longitude", -76.9353889, …
"TransmitterPower", 10);
txs = txsite("AntennaHeight", 1.5, …
"Latitude", 38.9860195, "Longitude", -76.9412203);
rays = raytrace(txs, rxs, pm, "type", "power"); % rays is Na x Ns cell array
if ~isempty(rays{1}) % only ever 1 tx/1 rx
rayPower = 0;
% phasor sum of rec’d power
for rayPath = 1:numel(rays{1})
pWatts = 10^(-rays{1}(rayPath).PathLoss/10)*10;
rayPower = rayPower + pWatts*(cos(rays{1}(rayPath).PhaseShift) + 1i*sin(rays{1}(rayPath).PhaseShift));
end
% convert to RSS in dBm and resultant signal phase offset
RSS = 10*log10(abs(rayPower)/.001); % dBm
phaseOffset = angle(rayPower) ; % rads
% collate data
data = [samplePoints(step, 1), samplePoints(step, 2), RSS, phaseOffset];
end
close all force % this is an attempt to fix this issue
save("data.mat","data")
The above code works as expected however, running:
load("data.mat")
Will result in the following warnings being spammed in the console:
> In <FUNCTION> (line 25)
Warning: Unable to load C++ object. Saving (serializing) C++ objects into a MAT-file is not supported.
> In <FUNCTION> (line 25)
Warning: Cannot load an object of class ‘proplistener’:
No matching constructor signature found.
> In <FUNCTION> (line 25)
Warning: During load:
An invalid default object has been detected while loading a heterogeneous array of class event.proplistener. An empty array of
class event.proplistener will be returned.
> In <FUNCTION> (line 25)
Warning: While loading an object of class ‘siteviewer’:
Unrecognized field name "Name".
I thought foriclby closing the siteviewer would work (or at least get rid of the last error), but it has not seemed to have an effect. What command should I run to fix this behavior?
Tested on 2023b, 2024b and the 2025 prerelease across two computers (one Win10, one Ubuntu22) which both had similar behaviors, although the Windows mahcine produced far fewer warnings. Example code:
txs = txsite("AntennaHeight",1.5, …
"Latitude", 38.9899587, "Longitude", -76.9353889, …
"TransmitterPower", 10);
txs = txsite("AntennaHeight", 1.5, …
"Latitude", 38.9860195, "Longitude", -76.9412203);
rays = raytrace(txs, rxs, pm, "type", "power"); % rays is Na x Ns cell array
if ~isempty(rays{1}) % only ever 1 tx/1 rx
rayPower = 0;
% phasor sum of rec’d power
for rayPath = 1:numel(rays{1})
pWatts = 10^(-rays{1}(rayPath).PathLoss/10)*10;
rayPower = rayPower + pWatts*(cos(rays{1}(rayPath).PhaseShift) + 1i*sin(rays{1}(rayPath).PhaseShift));
end
% convert to RSS in dBm and resultant signal phase offset
RSS = 10*log10(abs(rayPower)/.001); % dBm
phaseOffset = angle(rayPower) ; % rads
% collate data
data = [samplePoints(step, 1), samplePoints(step, 2), RSS, phaseOffset];
end
close all force % this is an attempt to fix this issue
save("data.mat","data")
The above code works as expected however, running:
load("data.mat")
Will result in the following warnings being spammed in the console:
> In <FUNCTION> (line 25)
Warning: Unable to load C++ object. Saving (serializing) C++ objects into a MAT-file is not supported.
> In <FUNCTION> (line 25)
Warning: Cannot load an object of class ‘proplistener’:
No matching constructor signature found.
> In <FUNCTION> (line 25)
Warning: During load:
An invalid default object has been detected while loading a heterogeneous array of class event.proplistener. An empty array of
class event.proplistener will be returned.
> In <FUNCTION> (line 25)
Warning: While loading an object of class ‘siteviewer’:
Unrecognized field name "Name".
I thought foriclby closing the siteviewer would work (or at least get rid of the last error), but it has not seemed to have an effect. What command should I run to fix this behavior?
Tested on 2023b, 2024b and the 2025 prerelease across two computers (one Win10, one Ubuntu22) which both had similar behaviors, although the Windows mahcine produced far fewer warnings. rf propagation, raytracing MATLAB Answers — New Questions
Can not find TLC file
<</matlabcentral/answers/uploaded_files/1823366/tlc.jpg>><</matlabcentral/answers/uploaded_files/1823366/tlc.jpg>> <</matlabcentral/answers/uploaded_files/1823366/tlc.jpg>> tlc file MATLAB Answers — New Questions
What is the best kind of MATLAB function to teach beginners?
Several releases ago (R2015a?), I would introduce students to MATLAB by getting them to plot graphs of simple functions. I would give fplot(‘sin(x)’, [-10,10]) as an example and then ask them to plot . They would type fplot(‘x^3’, [-10,10]) and get a message about needing to use element-wise operators. That was constructive advice which could be explained by saying that .^ is an element-wise operator.
Then character-array functions were deprecated. I changed my example to fplot(@(x) sin(x), [-10,10]), they now type fplot(@(x) x^3, [-10,10]) and get the warning "Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments". That is quite hard to explain, partly because our course has not yet covered vectors.
My question is: Is there a better way to introduce functions? Perhaps by using symbolic functions. MATLAB is continually introducing new kinds of functions (anonymous, local, nested, …) and I want to avoid teaching obsolete forms.Several releases ago (R2015a?), I would introduce students to MATLAB by getting them to plot graphs of simple functions. I would give fplot(‘sin(x)’, [-10,10]) as an example and then ask them to plot . They would type fplot(‘x^3’, [-10,10]) and get a message about needing to use element-wise operators. That was constructive advice which could be explained by saying that .^ is an element-wise operator.
Then character-array functions were deprecated. I changed my example to fplot(@(x) sin(x), [-10,10]), they now type fplot(@(x) x^3, [-10,10]) and get the warning "Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments". That is quite hard to explain, partly because our course has not yet covered vectors.
My question is: Is there a better way to introduce functions? Perhaps by using symbolic functions. MATLAB is continually introducing new kinds of functions (anonymous, local, nested, …) and I want to avoid teaching obsolete forms. Several releases ago (R2015a?), I would introduce students to MATLAB by getting them to plot graphs of simple functions. I would give fplot(‘sin(x)’, [-10,10]) as an example and then ask them to plot . They would type fplot(‘x^3’, [-10,10]) and get a message about needing to use element-wise operators. That was constructive advice which could be explained by saying that .^ is an element-wise operator.
Then character-array functions were deprecated. I changed my example to fplot(@(x) sin(x), [-10,10]), they now type fplot(@(x) x^3, [-10,10]) and get the warning "Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments". That is quite hard to explain, partly because our course has not yet covered vectors.
My question is: Is there a better way to introduce functions? Perhaps by using symbolic functions. MATLAB is continually introducing new kinds of functions (anonymous, local, nested, …) and I want to avoid teaching obsolete forms. functions, element-wise operators MATLAB Answers — New Questions
Parameter Identification of quarter car model
Hey guys,
I got the following system of a quarter car model:
The goal is to identify the unknown parameters of m1, m2, K, Kt and C based on differnt inputs q and outputs z1 and z2.
For this I simulated the model in Simulink with for example a sine wave as input q and set variables of m1, m2, K, Kt and C. I then recorded the position, motion and acceleration of z1 and z2.
Now lets say I only know the input q, output z1,z2 as well as their derivatives and I also got the equations of motion. I want to identify the unknown parameters m1, m2, K, Kt and C and see how close the identification gets compared to the values i defined in the simulink model.
I’d be glad if someone could give me hint as to how achieve this. Thanks for that.Hey guys,
I got the following system of a quarter car model:
The goal is to identify the unknown parameters of m1, m2, K, Kt and C based on differnt inputs q and outputs z1 and z2.
For this I simulated the model in Simulink with for example a sine wave as input q and set variables of m1, m2, K, Kt and C. I then recorded the position, motion and acceleration of z1 and z2.
Now lets say I only know the input q, output z1,z2 as well as their derivatives and I also got the equations of motion. I want to identify the unknown parameters m1, m2, K, Kt and C and see how close the identification gets compared to the values i defined in the simulink model.
I’d be glad if someone could give me hint as to how achieve this. Thanks for that. Hey guys,
I got the following system of a quarter car model:
The goal is to identify the unknown parameters of m1, m2, K, Kt and C based on differnt inputs q and outputs z1 and z2.
For this I simulated the model in Simulink with for example a sine wave as input q and set variables of m1, m2, K, Kt and C. I then recorded the position, motion and acceleration of z1 and z2.
Now lets say I only know the input q, output z1,z2 as well as their derivatives and I also got the equations of motion. I want to identify the unknown parameters m1, m2, K, Kt and C and see how close the identification gets compared to the values i defined in the simulink model.
I’d be glad if someone could give me hint as to how achieve this. Thanks for that. quarter car model, parameter identification, vehicle dynamics MATLAB Answers — New Questions
Li-ion battery calibration – Not able to disable parallel computing
Hi, I am trying to run the calibration process described in the following example provided by matlab:
https://www.mathworks.com/help/autoblks/ref/battery.pulsesequence.estimateparameters.html
It is a script to estimate battery parameters based on "psObj — Instance of Battery.PulseSequence" class.
I have all the toolbox required to run the simulation. However, I do not have the parallel computing toolbox. So in the code I have changed the optimization parameters to take this in consideration:
SDOOptimizeOptions = sdo.OptimizeOptions(…
‘OptimizedModel’,psObj.ModelName,…
‘Method’,’lsqnonlin’,…
‘UseParallel’,false);
SDOOptimizeOptions.MethodOptions.Display = ‘final’;
psObj.estimateParameters(…
‘CarryParamToNextPulse’,true,… %Set this true to use the final parameter values from the prior pulse and SOC as initial values for the next pulse and SOC
‘SDOOptimizeOptions’,SDOOptimizeOptions,… %Specify the SDO options object
‘ShowPlots’,true,… %Set this true if you want to see plots while this runs
‘EstimateEm’,true,… %Set this true to allow the optimizer to change Em further in this step
‘RetainEm’,true,… %Set this true keep any changes made to Em in this step
‘EstimateR0’,true,… %Set this true to allow the optimizer to change R0 further in this step
‘RetainR0’,true); %Set this true keep any changes made to R0 in this step
I set "UseParallel" to false.
But I get an error message when running line:
psObj.estimateParameters(…
The error message is:
gcp requires Parallel Computing Toolbox.
Error in Battery.DistributedParameterManager/distributeParameters
Error in Battery.PulseSequence/estimateParameters
What I am I doing wrong here?
Matlab version 24.2.0.2806996 (R2024b) Update 3, just installed is.
Thank youHi, I am trying to run the calibration process described in the following example provided by matlab:
https://www.mathworks.com/help/autoblks/ref/battery.pulsesequence.estimateparameters.html
It is a script to estimate battery parameters based on "psObj — Instance of Battery.PulseSequence" class.
I have all the toolbox required to run the simulation. However, I do not have the parallel computing toolbox. So in the code I have changed the optimization parameters to take this in consideration:
SDOOptimizeOptions = sdo.OptimizeOptions(…
‘OptimizedModel’,psObj.ModelName,…
‘Method’,’lsqnonlin’,…
‘UseParallel’,false);
SDOOptimizeOptions.MethodOptions.Display = ‘final’;
psObj.estimateParameters(…
‘CarryParamToNextPulse’,true,… %Set this true to use the final parameter values from the prior pulse and SOC as initial values for the next pulse and SOC
‘SDOOptimizeOptions’,SDOOptimizeOptions,… %Specify the SDO options object
‘ShowPlots’,true,… %Set this true if you want to see plots while this runs
‘EstimateEm’,true,… %Set this true to allow the optimizer to change Em further in this step
‘RetainEm’,true,… %Set this true keep any changes made to Em in this step
‘EstimateR0’,true,… %Set this true to allow the optimizer to change R0 further in this step
‘RetainR0’,true); %Set this true keep any changes made to R0 in this step
I set "UseParallel" to false.
But I get an error message when running line:
psObj.estimateParameters(…
The error message is:
gcp requires Parallel Computing Toolbox.
Error in Battery.DistributedParameterManager/distributeParameters
Error in Battery.PulseSequence/estimateParameters
What I am I doing wrong here?
Matlab version 24.2.0.2806996 (R2024b) Update 3, just installed is.
Thank you Hi, I am trying to run the calibration process described in the following example provided by matlab:
https://www.mathworks.com/help/autoblks/ref/battery.pulsesequence.estimateparameters.html
It is a script to estimate battery parameters based on "psObj — Instance of Battery.PulseSequence" class.
I have all the toolbox required to run the simulation. However, I do not have the parallel computing toolbox. So in the code I have changed the optimization parameters to take this in consideration:
SDOOptimizeOptions = sdo.OptimizeOptions(…
‘OptimizedModel’,psObj.ModelName,…
‘Method’,’lsqnonlin’,…
‘UseParallel’,false);
SDOOptimizeOptions.MethodOptions.Display = ‘final’;
psObj.estimateParameters(…
‘CarryParamToNextPulse’,true,… %Set this true to use the final parameter values from the prior pulse and SOC as initial values for the next pulse and SOC
‘SDOOptimizeOptions’,SDOOptimizeOptions,… %Specify the SDO options object
‘ShowPlots’,true,… %Set this true if you want to see plots while this runs
‘EstimateEm’,true,… %Set this true to allow the optimizer to change Em further in this step
‘RetainEm’,true,… %Set this true keep any changes made to Em in this step
‘EstimateR0’,true,… %Set this true to allow the optimizer to change R0 further in this step
‘RetainR0’,true); %Set this true keep any changes made to R0 in this step
I set "UseParallel" to false.
But I get an error message when running line:
psObj.estimateParameters(…
The error message is:
gcp requires Parallel Computing Toolbox.
Error in Battery.DistributedParameterManager/distributeParameters
Error in Battery.PulseSequence/estimateParameters
What I am I doing wrong here?
Matlab version 24.2.0.2806996 (R2024b) Update 3, just installed is.
Thank you sdooptimizeoptions parallel computing management MATLAB Answers — New Questions
Code won’t run on Mac due to backslashes
I have a pretty extensive software consisting of multiple .m and .mat files. Code is supposed to have some processing done and results saved based on imported files. There are dynamic paths and absolute paths in the code which are written for Windows (with backslash). When I run the code on Mac, code crashes due to this. I wanted to run a script which will replace all backslashes with forwardslashes in all the .m and .mat files. Issue here is that there are also escape sequences (like newline and others) which must use backslash. So I can’t run the script as it would mess up escape sequences. I fell back to running code on Windows machine. Is there really no chance of somehow setting execution on higher lever and ordering Matlab to always convert paths? I feel it is a simple issue with a complex solution and it should not exist at all.I have a pretty extensive software consisting of multiple .m and .mat files. Code is supposed to have some processing done and results saved based on imported files. There are dynamic paths and absolute paths in the code which are written for Windows (with backslash). When I run the code on Mac, code crashes due to this. I wanted to run a script which will replace all backslashes with forwardslashes in all the .m and .mat files. Issue here is that there are also escape sequences (like newline and others) which must use backslash. So I can’t run the script as it would mess up escape sequences. I fell back to running code on Windows machine. Is there really no chance of somehow setting execution on higher lever and ordering Matlab to always convert paths? I feel it is a simple issue with a complex solution and it should not exist at all. I have a pretty extensive software consisting of multiple .m and .mat files. Code is supposed to have some processing done and results saved based on imported files. There are dynamic paths and absolute paths in the code which are written for Windows (with backslash). When I run the code on Mac, code crashes due to this. I wanted to run a script which will replace all backslashes with forwardslashes in all the .m and .mat files. Issue here is that there are also escape sequences (like newline and others) which must use backslash. So I can’t run the script as it would mess up escape sequences. I fell back to running code on Windows machine. Is there really no chance of somehow setting execution on higher lever and ordering Matlab to always convert paths? I feel it is a simple issue with a complex solution and it should not exist at all. backslash MATLAB Answers — New Questions
Controlling a bidirectional AC/DC converter stable with no power transfer
I’m trying to model a bidirectional AC/DC converter that can both transfer power from AC to DC and vice versa. Also, when set to zero no power (P*=0) should be exchanged, which is the case in the model attached to this question. I’m trying to control the voltage over the capacitor (Vc) at the DC side (which is in this case 400V) and the reactive current to zero (Iq*=0). Unfortunatly, only the DC voltage over the capacitor as well as the power transfer are controlled "correctly" (both go at least to the reference values). The d component of the current at the AC side (Id) is for some reason going to 1000A while it should be around 0A, with no power transfer. Furthermore, the q component of the current at the AC side (Ic) is controlled to go to 0, which is also not the case at this moment.
Does anyone has an idea what I’m doing wrong? I hope when this works I can change the value of the power exchange between both sides to nonzero values, while the converter still behaves as planned.
Please let me know!
Kind regards,
SándorI’m trying to model a bidirectional AC/DC converter that can both transfer power from AC to DC and vice versa. Also, when set to zero no power (P*=0) should be exchanged, which is the case in the model attached to this question. I’m trying to control the voltage over the capacitor (Vc) at the DC side (which is in this case 400V) and the reactive current to zero (Iq*=0). Unfortunatly, only the DC voltage over the capacitor as well as the power transfer are controlled "correctly" (both go at least to the reference values). The d component of the current at the AC side (Id) is for some reason going to 1000A while it should be around 0A, with no power transfer. Furthermore, the q component of the current at the AC side (Ic) is controlled to go to 0, which is also not the case at this moment.
Does anyone has an idea what I’m doing wrong? I hope when this works I can change the value of the power exchange between both sides to nonzero values, while the converter still behaves as planned.
Please let me know!
Kind regards,
Sándor I’m trying to model a bidirectional AC/DC converter that can both transfer power from AC to DC and vice versa. Also, when set to zero no power (P*=0) should be exchanged, which is the case in the model attached to this question. I’m trying to control the voltage over the capacitor (Vc) at the DC side (which is in this case 400V) and the reactive current to zero (Iq*=0). Unfortunatly, only the DC voltage over the capacitor as well as the power transfer are controlled "correctly" (both go at least to the reference values). The d component of the current at the AC side (Id) is for some reason going to 1000A while it should be around 0A, with no power transfer. Furthermore, the q component of the current at the AC side (Ic) is controlled to go to 0, which is also not the case at this moment.
Does anyone has an idea what I’m doing wrong? I hope when this works I can change the value of the power exchange between both sides to nonzero values, while the converter still behaves as planned.
Please let me know!
Kind regards,
Sándor ac/dc, bidirectional, voltage control, converter, simulink, hybrid microgrid MATLAB Answers — New Questions
How can I insert data into rows without looping and logical indexing?
I have two tables. table1 is 10*5 and table2 is 5*10.
table1 = table;
table1.var1 = [1; 1; 3; 3; 6; 1; 1; 3; 3; 6];
table1.var2 = [1; 2; 2; 3; 6; 1; 2; 2; 3; 6];
table1.var3 = [0; 2; 3; 4; 6; 0; 2; 3; 4; 6];
table1.var4 = [0; 2; 1; 5; 6; 0; 2; 1; 5; 6];
table1.var5 = [0; 2; 8; 7; 6; 0; 2; 8; 7; 6];
table2 = table;
table2.var1 = [1; 1; 3; 4; 5];
table2.var2 = [1; 2; 2; 5; 5];
table2.var3 = [1; 3; 3; 4; 5];
table2.var4 = [1; 2; 3; 4; 5];
table2.var5 = [1; 2; 4; 4; 5];
table2.var6 = [1; 8; 3; 4; 5];
table2.var7 = [1; 9; 3; 4; 5];
table2.var8 = [1; 7; 3; 4; 5];
table2.var9 = [1; 2; 3; 4; 5];
table2.var10 = [0; 1; 2; 3; 4];
test = table2(ismember(…
[table2.var1, table2.var2],…
[table1.var1, table1.var2], ‘rows’), :);
How can I take var7 and var8 from test and input them in the matching rows from table1?
the output should look something like:
table1.var1 = [1; 1; 3; 3; 6; 1; 1; 3; 3; 6];
table1.var2 = [1; 2; 2; 3; 6; 1; 2; 2; 3; 6];
table1.var3 = [0; 2; 3; 4; 6; 0; 2; 3; 4; 6];
table1.var4 = [0; 2; 1; 5; 6; 0; 2; 1; 5; 6];
table1.var5 = [0; 2; 8; 7; 6; 0; 2; 8; 7; 6];
table1.var6 = [1; 9; 3; 0; 0; 1; 9; 3; 0; 0];
table1.var7 = [1; 7; 3; 0; 0; 1; 7; 3; 0; 0];
I can complete this with looping and logicaly indexing but would like to optimze for speed. Is there a faster way?
Can I directly insert table2.var7 and table2.var8 into table1 at every row were [table2.var1, table2.var] are the same rows of [table1.var1, table1.var2]? If so, how?I have two tables. table1 is 10*5 and table2 is 5*10.
table1 = table;
table1.var1 = [1; 1; 3; 3; 6; 1; 1; 3; 3; 6];
table1.var2 = [1; 2; 2; 3; 6; 1; 2; 2; 3; 6];
table1.var3 = [0; 2; 3; 4; 6; 0; 2; 3; 4; 6];
table1.var4 = [0; 2; 1; 5; 6; 0; 2; 1; 5; 6];
table1.var5 = [0; 2; 8; 7; 6; 0; 2; 8; 7; 6];
table2 = table;
table2.var1 = [1; 1; 3; 4; 5];
table2.var2 = [1; 2; 2; 5; 5];
table2.var3 = [1; 3; 3; 4; 5];
table2.var4 = [1; 2; 3; 4; 5];
table2.var5 = [1; 2; 4; 4; 5];
table2.var6 = [1; 8; 3; 4; 5];
table2.var7 = [1; 9; 3; 4; 5];
table2.var8 = [1; 7; 3; 4; 5];
table2.var9 = [1; 2; 3; 4; 5];
table2.var10 = [0; 1; 2; 3; 4];
test = table2(ismember(…
[table2.var1, table2.var2],…
[table1.var1, table1.var2], ‘rows’), :);
How can I take var7 and var8 from test and input them in the matching rows from table1?
the output should look something like:
table1.var1 = [1; 1; 3; 3; 6; 1; 1; 3; 3; 6];
table1.var2 = [1; 2; 2; 3; 6; 1; 2; 2; 3; 6];
table1.var3 = [0; 2; 3; 4; 6; 0; 2; 3; 4; 6];
table1.var4 = [0; 2; 1; 5; 6; 0; 2; 1; 5; 6];
table1.var5 = [0; 2; 8; 7; 6; 0; 2; 8; 7; 6];
table1.var6 = [1; 9; 3; 0; 0; 1; 9; 3; 0; 0];
table1.var7 = [1; 7; 3; 0; 0; 1; 7; 3; 0; 0];
I can complete this with looping and logicaly indexing but would like to optimze for speed. Is there a faster way?
Can I directly insert table2.var7 and table2.var8 into table1 at every row were [table2.var1, table2.var] are the same rows of [table1.var1, table1.var2]? If so, how? I have two tables. table1 is 10*5 and table2 is 5*10.
table1 = table;
table1.var1 = [1; 1; 3; 3; 6; 1; 1; 3; 3; 6];
table1.var2 = [1; 2; 2; 3; 6; 1; 2; 2; 3; 6];
table1.var3 = [0; 2; 3; 4; 6; 0; 2; 3; 4; 6];
table1.var4 = [0; 2; 1; 5; 6; 0; 2; 1; 5; 6];
table1.var5 = [0; 2; 8; 7; 6; 0; 2; 8; 7; 6];
table2 = table;
table2.var1 = [1; 1; 3; 4; 5];
table2.var2 = [1; 2; 2; 5; 5];
table2.var3 = [1; 3; 3; 4; 5];
table2.var4 = [1; 2; 3; 4; 5];
table2.var5 = [1; 2; 4; 4; 5];
table2.var6 = [1; 8; 3; 4; 5];
table2.var7 = [1; 9; 3; 4; 5];
table2.var8 = [1; 7; 3; 4; 5];
table2.var9 = [1; 2; 3; 4; 5];
table2.var10 = [0; 1; 2; 3; 4];
test = table2(ismember(…
[table2.var1, table2.var2],…
[table1.var1, table1.var2], ‘rows’), :);
How can I take var7 and var8 from test and input them in the matching rows from table1?
the output should look something like:
table1.var1 = [1; 1; 3; 3; 6; 1; 1; 3; 3; 6];
table1.var2 = [1; 2; 2; 3; 6; 1; 2; 2; 3; 6];
table1.var3 = [0; 2; 3; 4; 6; 0; 2; 3; 4; 6];
table1.var4 = [0; 2; 1; 5; 6; 0; 2; 1; 5; 6];
table1.var5 = [0; 2; 8; 7; 6; 0; 2; 8; 7; 6];
table1.var6 = [1; 9; 3; 0; 0; 1; 9; 3; 0; 0];
table1.var7 = [1; 7; 3; 0; 0; 1; 7; 3; 0; 0];
I can complete this with looping and logicaly indexing but would like to optimze for speed. Is there a faster way?
Can I directly insert table2.var7 and table2.var8 into table1 at every row were [table2.var1, table2.var] are the same rows of [table1.var1, table1.var2]? If so, how? table, indexing, for loop, variables, optimization, speed, cell array, array, arrays, cell arrays MATLAB Answers — New Questions
Take 3×3 nearest neighbours round centroids of all spots and find the median of their mean
Hello, I have an image (TIFF) that I calculate the centroids and extract the median intensity of all these centroids.
I have the centroid positons in x1,y1 and loop through them the obtin the intensity of each spot and then take the median
Intensity(i)=IM(y1(i),x1(i)); %Centroid intensity
…
medIntensity=median(Intensity(:));
I now want to take a 3×3 nearest neighbours round each of the x1,y1 points and obtain the median of their mean.
Are there any suggestions how I achieve this.
Thanks
JasonHello, I have an image (TIFF) that I calculate the centroids and extract the median intensity of all these centroids.
I have the centroid positons in x1,y1 and loop through them the obtin the intensity of each spot and then take the median
Intensity(i)=IM(y1(i),x1(i)); %Centroid intensity
…
medIntensity=median(Intensity(:));
I now want to take a 3×3 nearest neighbours round each of the x1,y1 points and obtain the median of their mean.
Are there any suggestions how I achieve this.
Thanks
Jason Hello, I have an image (TIFF) that I calculate the centroids and extract the median intensity of all these centroids.
I have the centroid positons in x1,y1 and loop through them the obtin the intensity of each spot and then take the median
Intensity(i)=IM(y1(i),x1(i)); %Centroid intensity
…
medIntensity=median(Intensity(:));
I now want to take a 3×3 nearest neighbours round each of the x1,y1 points and obtain the median of their mean.
Are there any suggestions how I achieve this.
Thanks
Jason image, centroid MATLAB Answers — New Questions
Explicitly Multiplication of Matrices using For Loops
I understand the concept of this, but only for when the matrices are the same size.
I now have Matrix A which is a 3×5 matrix and Matrix B which is a 5×4 matrix. I want to multiply the two explicitly using For loops. Can anyone help ?
Thanks in advance !I understand the concept of this, but only for when the matrices are the same size.
I now have Matrix A which is a 3×5 matrix and Matrix B which is a 5×4 matrix. I want to multiply the two explicitly using For loops. Can anyone help ?
Thanks in advance ! I understand the concept of this, but only for when the matrices are the same size.
I now have Matrix A which is a 3×5 matrix and Matrix B which is a 5×4 matrix. I want to multiply the two explicitly using For loops. Can anyone help ?
Thanks in advance ! for loop, matrix MATLAB Answers — New Questions
Find Max Delta of Sliding 3×3 Window Over Matrix
I have the code below to find the max delta between a point and its 8 neighbors in a sliding 3×3 window. I do this for the whole matrix input, A. This works fine and correct, but I am wondering if this can be accomplished with several uses of conv2 instead of the imerode/imdilation calls. The computation I’m doing is depicted in the attached image.
% This method works fine…
A = magic(3); % Test case
% This finds the max diff
% between a pixel and its 8 neighbors.
drMin = min(A(:)); drMax = max(A(:)); % Phantom (padding) pts outside of domain are assumed the avg.
padPt = mean([drMin drMax]); % Value to use for padding.
tmp1 = padarray(A,1,padPt,’both’); tmp2 = padarray(tmp1′,1,padPt,’both’); Apad = tmp2′; % Pad matrix.
maxApad = imdilate(Apad,ones(3)) – Apad; % Local max minus the map. Delta from each pt to max neighbor.
minApad = imerode(Apad,ones(3)) – Apad; % Local min minus the map. Delta from each pt to min neighbor.
tmp(:,:,1) = abs(maxApad); tmp(:,:,2) = abs(minApad);
Ctmp = max(tmp,[],3); % Largest of the two gives the max delta from each point to its neighbors!
C = Ctmp(2:end-1,2:end-1); % Remove padding…
The expected result for the magic(3) input is:
7 7 5
6 4 6
5 7 7
I have tried with the following code, but it’s clearly off.
A = magic(3);
arrayTot = zeros(3,3,8);
kernel = zeros([9 1]); kernel(5) = 1;
for k = 1:9
if k ~=5
kernel(k) = -1;
k1 = kernel;
k1 = reshape(k1,[3 3]);
tmp = conv2(A,k1,’same’);
arrayTot(:,:,k) = abs(tmp);
kernel = zeros([9 1]); kernel(5) = 1;
end
end
tst = max(arrayTot,[],3)
Any advice would be appreciated. Thanks.I have the code below to find the max delta between a point and its 8 neighbors in a sliding 3×3 window. I do this for the whole matrix input, A. This works fine and correct, but I am wondering if this can be accomplished with several uses of conv2 instead of the imerode/imdilation calls. The computation I’m doing is depicted in the attached image.
% This method works fine…
A = magic(3); % Test case
% This finds the max diff
% between a pixel and its 8 neighbors.
drMin = min(A(:)); drMax = max(A(:)); % Phantom (padding) pts outside of domain are assumed the avg.
padPt = mean([drMin drMax]); % Value to use for padding.
tmp1 = padarray(A,1,padPt,’both’); tmp2 = padarray(tmp1′,1,padPt,’both’); Apad = tmp2′; % Pad matrix.
maxApad = imdilate(Apad,ones(3)) – Apad; % Local max minus the map. Delta from each pt to max neighbor.
minApad = imerode(Apad,ones(3)) – Apad; % Local min minus the map. Delta from each pt to min neighbor.
tmp(:,:,1) = abs(maxApad); tmp(:,:,2) = abs(minApad);
Ctmp = max(tmp,[],3); % Largest of the two gives the max delta from each point to its neighbors!
C = Ctmp(2:end-1,2:end-1); % Remove padding…
The expected result for the magic(3) input is:
7 7 5
6 4 6
5 7 7
I have tried with the following code, but it’s clearly off.
A = magic(3);
arrayTot = zeros(3,3,8);
kernel = zeros([9 1]); kernel(5) = 1;
for k = 1:9
if k ~=5
kernel(k) = -1;
k1 = kernel;
k1 = reshape(k1,[3 3]);
tmp = conv2(A,k1,’same’);
arrayTot(:,:,k) = abs(tmp);
kernel = zeros([9 1]); kernel(5) = 1;
end
end
tst = max(arrayTot,[],3)
Any advice would be appreciated. Thanks. I have the code below to find the max delta between a point and its 8 neighbors in a sliding 3×3 window. I do this for the whole matrix input, A. This works fine and correct, but I am wondering if this can be accomplished with several uses of conv2 instead of the imerode/imdilation calls. The computation I’m doing is depicted in the attached image.
% This method works fine…
A = magic(3); % Test case
% This finds the max diff
% between a pixel and its 8 neighbors.
drMin = min(A(:)); drMax = max(A(:)); % Phantom (padding) pts outside of domain are assumed the avg.
padPt = mean([drMin drMax]); % Value to use for padding.
tmp1 = padarray(A,1,padPt,’both’); tmp2 = padarray(tmp1′,1,padPt,’both’); Apad = tmp2′; % Pad matrix.
maxApad = imdilate(Apad,ones(3)) – Apad; % Local max minus the map. Delta from each pt to max neighbor.
minApad = imerode(Apad,ones(3)) – Apad; % Local min minus the map. Delta from each pt to min neighbor.
tmp(:,:,1) = abs(maxApad); tmp(:,:,2) = abs(minApad);
Ctmp = max(tmp,[],3); % Largest of the two gives the max delta from each point to its neighbors!
C = Ctmp(2:end-1,2:end-1); % Remove padding…
The expected result for the magic(3) input is:
7 7 5
6 4 6
5 7 7
I have tried with the following code, but it’s clearly off.
A = magic(3);
arrayTot = zeros(3,3,8);
kernel = zeros([9 1]); kernel(5) = 1;
for k = 1:9
if k ~=5
kernel(k) = -1;
k1 = kernel;
k1 = reshape(k1,[3 3]);
tmp = conv2(A,k1,’same’);
arrayTot(:,:,k) = abs(tmp);
kernel = zeros([9 1]); kernel(5) = 1;
end
end
tst = max(arrayTot,[],3)
Any advice would be appreciated. Thanks. convolution, image processing, imdilate, imerode MATLAB Answers — New Questions
PV array with DC-DC buck boost Converter
Hi I am trying to modelling a PV array with a DC-DC buck-boost converter.
When I run my simulink file I get errors related to algebraic loops (as seen in the appendix) and I don’t know how to solve them.
File 1 image corresponds to power_BBC1 file and file 2 image corresponds to power_BBC2 file.
I would like your help if possible.
Best regards,
Diogo RemoaldoHi I am trying to modelling a PV array with a DC-DC buck-boost converter.
When I run my simulink file I get errors related to algebraic loops (as seen in the appendix) and I don’t know how to solve them.
File 1 image corresponds to power_BBC1 file and file 2 image corresponds to power_BBC2 file.
I would like your help if possible.
Best regards,
Diogo Remoaldo Hi I am trying to modelling a PV array with a DC-DC buck-boost converter.
When I run my simulink file I get errors related to algebraic loops (as seen in the appendix) and I don’t know how to solve them.
File 1 image corresponds to power_BBC1 file and file 2 image corresponds to power_BBC2 file.
I would like your help if possible.
Best regards,
Diogo Remoaldo pv_array, dc-dc converter MATLAB Answers — New Questions
Find Masked Requirement Tables
I am using the slreq.modeling.find() function to pull the requirement tables from a model. I would like to also pull the masked tables form the same model but this function seems to miss those elements. How can I pull the masked tables as well?I am using the slreq.modeling.find() function to pull the requirement tables from a model. I would like to also pull the masked tables form the same model but this function seems to miss those elements. How can I pull the masked tables as well? I am using the slreq.modeling.find() function to pull the requirement tables from a model. I would like to also pull the masked tables form the same model but this function seems to miss those elements. How can I pull the masked tables as well? #requirementstables MATLAB Answers — New Questions
Function working as a matlab script but not working when copied into a simulink block (Matlab Function)
I am trying to use the following code inside a Matlab Function Block of Simulink, its giving me size mismatch error while building the model. But when the same code written as a matlab script and executed, works perfectly. I suspect there error arises because of how load function works for simulink. Can anyone explain to me how to modify the code to avoid this error?
data = coder.load("values.mat");
a = {data.w.l_0,data.w.l_1,data.w.l_2};
b = {data.g.l_0, data.g.l_1, data.g.l_2};
b = {data.s.l_0, data.s.l_1, data.s.l_2};
ctl = 0.0;
x = [0.3,0.03,0.03,0.03];
ctl = compute_output(x, a, b, c, 3);I am trying to use the following code inside a Matlab Function Block of Simulink, its giving me size mismatch error while building the model. But when the same code written as a matlab script and executed, works perfectly. I suspect there error arises because of how load function works for simulink. Can anyone explain to me how to modify the code to avoid this error?
data = coder.load("values.mat");
a = {data.w.l_0,data.w.l_1,data.w.l_2};
b = {data.g.l_0, data.g.l_1, data.g.l_2};
b = {data.s.l_0, data.s.l_1, data.s.l_2};
ctl = 0.0;
x = [0.3,0.03,0.03,0.03];
ctl = compute_output(x, a, b, c, 3); I am trying to use the following code inside a Matlab Function Block of Simulink, its giving me size mismatch error while building the model. But when the same code written as a matlab script and executed, works perfectly. I suspect there error arises because of how load function works for simulink. Can anyone explain to me how to modify the code to avoid this error?
data = coder.load("values.mat");
a = {data.w.l_0,data.w.l_1,data.w.l_2};
b = {data.g.l_0, data.g.l_1, data.g.l_2};
b = {data.s.l_0, data.s.l_1, data.s.l_2};
ctl = 0.0;
x = [0.3,0.03,0.03,0.03];
ctl = compute_output(x, a, b, c, 3); load, simulink MATLAB Answers — New Questions
imerode/imdilate use convolution?
Do imerode and imdilate use a convolution (e.g. conv2) under the hood? The source code is not available with their respective .m files.
If they do not, what is the algorithm and could those operations also be accomplished with a convolution? If they do, what is the kernel?
Thanks!Do imerode and imdilate use a convolution (e.g. conv2) under the hood? The source code is not available with their respective .m files.
If they do not, what is the algorithm and could those operations also be accomplished with a convolution? If they do, what is the kernel?
Thanks! Do imerode and imdilate use a convolution (e.g. conv2) under the hood? The source code is not available with their respective .m files.
If they do not, what is the algorithm and could those operations also be accomplished with a convolution? If they do, what is the kernel?
Thanks! imerode, imdilation, image processing, convolution MATLAB Answers — New Questions
How to solve damped forced vibration analysis using ode45 ?
I am trying to solve equation of motion for a damped forced vibration analysis for a SDOF system. My input Force is function of time having random white noise. I am using ode45 to solve the problem. Here is my code.
% Main code
clear variables
close all
clc
t = 0:20; % Time duration
x = [1; 6]; % Initial conditions
[t, x] = ode45(@eqm,t,x); % ode45 command
Below is the function eqm
% Function
function dxdt = eqm(t, x)
F = 1:20 % For simplicity I have taken force as an array
m = 1; % mass
c = 1; % damping
k = 1; % stiffness
dxdt = [x(2); F/m – c/m*x(2) – k*x(1)];
end
After I run this code it shows error "Error using vertcat. Dimensions of arrays being concatenated are not consistent". I checked online but most of the examples contains only periodic functions of force such as F = sin(wt) but I didn’t find anything for random load. Any help will be greatly appreciated.I am trying to solve equation of motion for a damped forced vibration analysis for a SDOF system. My input Force is function of time having random white noise. I am using ode45 to solve the problem. Here is my code.
% Main code
clear variables
close all
clc
t = 0:20; % Time duration
x = [1; 6]; % Initial conditions
[t, x] = ode45(@eqm,t,x); % ode45 command
Below is the function eqm
% Function
function dxdt = eqm(t, x)
F = 1:20 % For simplicity I have taken force as an array
m = 1; % mass
c = 1; % damping
k = 1; % stiffness
dxdt = [x(2); F/m – c/m*x(2) – k*x(1)];
end
After I run this code it shows error "Error using vertcat. Dimensions of arrays being concatenated are not consistent". I checked online but most of the examples contains only periodic functions of force such as F = sin(wt) but I didn’t find anything for random load. Any help will be greatly appreciated. I am trying to solve equation of motion for a damped forced vibration analysis for a SDOF system. My input Force is function of time having random white noise. I am using ode45 to solve the problem. Here is my code.
% Main code
clear variables
close all
clc
t = 0:20; % Time duration
x = [1; 6]; % Initial conditions
[t, x] = ode45(@eqm,t,x); % ode45 command
Below is the function eqm
% Function
function dxdt = eqm(t, x)
F = 1:20 % For simplicity I have taken force as an array
m = 1; % mass
c = 1; % damping
k = 1; % stiffness
dxdt = [x(2); F/m – c/m*x(2) – k*x(1)];
end
After I run this code it shows error "Error using vertcat. Dimensions of arrays being concatenated are not consistent". I checked online but most of the examples contains only periodic functions of force such as F = sin(wt) but I didn’t find anything for random load. Any help will be greatly appreciated. ode45, differential equations MATLAB Answers — New Questions
How does the electrical circuit of a Battery work?
This is the electrical circuit of a Battery model i found in Matlab. And i want to know how does it work during the discharge and charge. Could anyone explain to me how the different elements behave when the current flows through the circuit?Here are the equations of charge and discharge :
<</matlabcentral/answers/uploaded_files/113619/equation%20of%20discharge%20and%20charge.jpeg>>
<</matlabcentral/answers/uploaded_files/113618/electrical%20circuit.png>>
Thank you for your HelpThis is the electrical circuit of a Battery model i found in Matlab. And i want to know how does it work during the discharge and charge. Could anyone explain to me how the different elements behave when the current flows through the circuit?Here are the equations of charge and discharge :
<</matlabcentral/answers/uploaded_files/113619/equation%20of%20discharge%20and%20charge.jpeg>>
<</matlabcentral/answers/uploaded_files/113618/electrical%20circuit.png>>
Thank you for your Help This is the electrical circuit of a Battery model i found in Matlab. And i want to know how does it work during the discharge and charge. Could anyone explain to me how the different elements behave when the current flows through the circuit?Here are the equations of charge and discharge :
<</matlabcentral/answers/uploaded_files/113619/equation%20of%20discharge%20and%20charge.jpeg>>
<</matlabcentral/answers/uploaded_files/113618/electrical%20circuit.png>>
Thank you for your Help electrical circuit of a battery, power_electronics_control, battery_system_management MATLAB Answers — New Questions