Tag Archives: matlab
Closing windows CMD window after executing system and run through a certain algorithm
I want to use ‘system’ to open another software in cmd as well as forming a java socket between them to allow exchanging datas for calculation, as shown in the code below
% command to execute in cmd to form socket
commandString = strcat(‘"’, this.FreeFlyerPath, ‘FreeFlyer.exe"’, …
‘ -r -mp "’, this.MissionPlanPath, ‘sample.MissionPlan"’, …
sprintf(‘ -ui %d -ui %d -ui %s &’, portNum(1), portNum(2), this.terminationCode));
system( commandString );
%
%
%
%
% some algorithms
%
%
%
% how to close the cmd?
However, the function has to be looped multiple times, that means the cmd windows keep popping out like a virus without exiting. I tried system(‘exit’) and it does not work. May I know the correct way to close the cmd window after executed the function?I want to use ‘system’ to open another software in cmd as well as forming a java socket between them to allow exchanging datas for calculation, as shown in the code below
% command to execute in cmd to form socket
commandString = strcat(‘"’, this.FreeFlyerPath, ‘FreeFlyer.exe"’, …
‘ -r -mp "’, this.MissionPlanPath, ‘sample.MissionPlan"’, …
sprintf(‘ -ui %d -ui %d -ui %s &’, portNum(1), portNum(2), this.terminationCode));
system( commandString );
%
%
%
%
% some algorithms
%
%
%
% how to close the cmd?
However, the function has to be looped multiple times, that means the cmd windows keep popping out like a virus without exiting. I tried system(‘exit’) and it does not work. May I know the correct way to close the cmd window after executed the function? I want to use ‘system’ to open another software in cmd as well as forming a java socket between them to allow exchanging datas for calculation, as shown in the code below
% command to execute in cmd to form socket
commandString = strcat(‘"’, this.FreeFlyerPath, ‘FreeFlyer.exe"’, …
‘ -r -mp "’, this.MissionPlanPath, ‘sample.MissionPlan"’, …
sprintf(‘ -ui %d -ui %d -ui %s &’, portNum(1), portNum(2), this.terminationCode));
system( commandString );
%
%
%
%
% some algorithms
%
%
%
% how to close the cmd?
However, the function has to be looped multiple times, that means the cmd windows keep popping out like a virus without exiting. I tried system(‘exit’) and it does not work. May I know the correct way to close the cmd window after executed the function? system, cmd, exit MATLAB Answers — New Questions
Problem in applying Genetic algorithm solver in matlab while solving the electric bus scheduling problem
I am using a Genetic Algorithm (GA) solver in MATLAB to solve the electric bus scheduling problem. The objective function is designed to minimize the cost of electric buses and chargers while incorporating vehicle flow and charging constraints. However, when I apply the solver, it seems to ignore the charging constraints. It only outputs the number of electric buses along with their schedules, without assigning any buses to chargers. The output for chargers consistently shows a value of zero. When I tested the same dataset using CPLEX, it successfully assigned electric buses to chargers. How can I resolve this issue?
% Solver options
options = optimoptions(‘ga’, …
‘Display’, ‘iter’, … % Display iteration details
‘PlotFcn’, ‘gaplotbestf’, … % Plot GA progress
‘MaxTime’, 5000, … % Maximum runtime in seconds
‘PopulationSize’, 100, … % GA population size
‘CrossoverFraction’, 0.8); % Fraction for crossover
% Solve the optimization problem
[sol, fval, exitflag, output] = solve(Busschedulling_A, ‘Solver’, ‘ga’, ‘Options’, options);I am using a Genetic Algorithm (GA) solver in MATLAB to solve the electric bus scheduling problem. The objective function is designed to minimize the cost of electric buses and chargers while incorporating vehicle flow and charging constraints. However, when I apply the solver, it seems to ignore the charging constraints. It only outputs the number of electric buses along with their schedules, without assigning any buses to chargers. The output for chargers consistently shows a value of zero. When I tested the same dataset using CPLEX, it successfully assigned electric buses to chargers. How can I resolve this issue?
% Solver options
options = optimoptions(‘ga’, …
‘Display’, ‘iter’, … % Display iteration details
‘PlotFcn’, ‘gaplotbestf’, … % Plot GA progress
‘MaxTime’, 5000, … % Maximum runtime in seconds
‘PopulationSize’, 100, … % GA population size
‘CrossoverFraction’, 0.8); % Fraction for crossover
% Solve the optimization problem
[sol, fval, exitflag, output] = solve(Busschedulling_A, ‘Solver’, ‘ga’, ‘Options’, options); I am using a Genetic Algorithm (GA) solver in MATLAB to solve the electric bus scheduling problem. The objective function is designed to minimize the cost of electric buses and chargers while incorporating vehicle flow and charging constraints. However, when I apply the solver, it seems to ignore the charging constraints. It only outputs the number of electric buses along with their schedules, without assigning any buses to chargers. The output for chargers consistently shows a value of zero. When I tested the same dataset using CPLEX, it successfully assigned electric buses to chargers. How can I resolve this issue?
% Solver options
options = optimoptions(‘ga’, …
‘Display’, ‘iter’, … % Display iteration details
‘PlotFcn’, ‘gaplotbestf’, … % Plot GA progress
‘MaxTime’, 5000, … % Maximum runtime in seconds
‘PopulationSize’, 100, … % GA population size
‘CrossoverFraction’, 0.8); % Fraction for crossover
% Solve the optimization problem
[sol, fval, exitflag, output] = solve(Busschedulling_A, ‘Solver’, ‘ga’, ‘Options’, options); genetic algorithm, matlab, optimization, programming MATLAB Answers — New Questions
Warning: Parameter object’s DataType property has been set while its Value is not double precision.
I have this warnings in matlab
Warning: Parameter object’s DataType property has been set while its Value is not double precision. Converting Value to real-world value (double precision).
I use .m file when declare parameter
and delare like this
Y.Value = [fi([0,10,10,0,0,0,0,0,0,0], 1, 16, 0.01, 0)];
When I enterend Y Value in command Window say like this
Parameter with properties:
Value: [0 10 10 0 0 0 0 0 0 0]
CoderInfo: [1×1 Simulink.CoderInfo]
Description: ‘-‘
DataType: ‘fixdt(0,16,0.01,0)’
Min: []
Max: []
Unit: ”
Complexity: ‘real’
Dimensions: [1 10]
Why this warning happens?I have this warnings in matlab
Warning: Parameter object’s DataType property has been set while its Value is not double precision. Converting Value to real-world value (double precision).
I use .m file when declare parameter
and delare like this
Y.Value = [fi([0,10,10,0,0,0,0,0,0,0], 1, 16, 0.01, 0)];
When I enterend Y Value in command Window say like this
Parameter with properties:
Value: [0 10 10 0 0 0 0 0 0 0]
CoderInfo: [1×1 Simulink.CoderInfo]
Description: ‘-‘
DataType: ‘fixdt(0,16,0.01,0)’
Min: []
Max: []
Unit: ”
Complexity: ‘real’
Dimensions: [1 10]
Why this warning happens? I have this warnings in matlab
Warning: Parameter object’s DataType property has been set while its Value is not double precision. Converting Value to real-world value (double precision).
I use .m file when declare parameter
and delare like this
Y.Value = [fi([0,10,10,0,0,0,0,0,0,0], 1, 16, 0.01, 0)];
When I enterend Y Value in command Window say like this
Parameter with properties:
Value: [0 10 10 0 0 0 0 0 0 0]
CoderInfo: [1×1 Simulink.CoderInfo]
Description: ‘-‘
DataType: ‘fixdt(0,16,0.01,0)’
Min: []
Max: []
Unit: ”
Complexity: ‘real’
Dimensions: [1 10]
Why this warning happens? simulink, matlab MATLAB Answers — New Questions
How to stop command window from pasting in previous commands?
I’ve been encountering a strange issue with my command windows as of recent. For some reason whenever I type something in, it will provide to paste previous prompts from the window about 20 times over. This results in the workspace becoming unusable. Does anyone know what might be causing this? I’m new to the system so its difficult for me to troubleshoot.I’ve been encountering a strange issue with my command windows as of recent. For some reason whenever I type something in, it will provide to paste previous prompts from the window about 20 times over. This results in the workspace becoming unusable. Does anyone know what might be causing this? I’m new to the system so its difficult for me to troubleshoot. I’ve been encountering a strange issue with my command windows as of recent. For some reason whenever I type something in, it will provide to paste previous prompts from the window about 20 times over. This results in the workspace becoming unusable. Does anyone know what might be causing this? I’m new to the system so its difficult for me to troubleshoot. help, matlab MATLAB Answers — New Questions
accessIntervals Function: Subscripting into a Table Using One Subscript Error
Problem Description:
I am working on a MATLAB project involving the Satellite Communications Toolbox. My script uses the accessIntervals function to compute access intervals for satellites and ground stations. However, I consistently encounter the following error:
sql
Copy code
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row subscript and a variable subscript, as in t(rows,vars). To select variables, use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
Steps to Reproduce:
I created a satellite scenario with the following setup:matlabCopy codestartTime = datetime(2024, 1, 6, 23, 23, 0);
stopTime = startTime + hours(24);
sampleTime = 60;
sc = satelliteScenario(startTime, stopTime, sampleTime);
sat = walkerDelta(sc, 570e3 + 6378.14e3, 70, 720, 36, 1, ArgumentOfLatitude=15, Name="Starlink");
gs = groundStation(sc, "Name", "Test Station", "Latitude", -35.40139, "Longitude", 148.98167);
ac = access(sat, gs);
I attempted to call accessIntervals for the Access object:matlabCopy codeTest = accessIntervals(ac(1));
The error occurs for all Access objects (ac).
Debugging Steps Taken:
I confirmed the Access objects (ac) are valid and properly initialized:matlabCopy codeAccess Object 1:
Access with properties:
Sequence: [1 721]
LineWidth: 3
LineColor: [0.3922 0.8314 0.0745]
The error persists for all Access objects.
Questions:
Is this a known issue with accessIntervals or the Satellite Communications Toolbox?
How can I resolve or work around this error to compute access intervals?
Are there alternative methods to compute satellite-ground station access intervals if accessIntervals cannot be used?
Environment: MatlabonlineProblem Description:
I am working on a MATLAB project involving the Satellite Communications Toolbox. My script uses the accessIntervals function to compute access intervals for satellites and ground stations. However, I consistently encounter the following error:
sql
Copy code
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row subscript and a variable subscript, as in t(rows,vars). To select variables, use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
Steps to Reproduce:
I created a satellite scenario with the following setup:matlabCopy codestartTime = datetime(2024, 1, 6, 23, 23, 0);
stopTime = startTime + hours(24);
sampleTime = 60;
sc = satelliteScenario(startTime, stopTime, sampleTime);
sat = walkerDelta(sc, 570e3 + 6378.14e3, 70, 720, 36, 1, ArgumentOfLatitude=15, Name="Starlink");
gs = groundStation(sc, "Name", "Test Station", "Latitude", -35.40139, "Longitude", 148.98167);
ac = access(sat, gs);
I attempted to call accessIntervals for the Access object:matlabCopy codeTest = accessIntervals(ac(1));
The error occurs for all Access objects (ac).
Debugging Steps Taken:
I confirmed the Access objects (ac) are valid and properly initialized:matlabCopy codeAccess Object 1:
Access with properties:
Sequence: [1 721]
LineWidth: 3
LineColor: [0.3922 0.8314 0.0745]
The error persists for all Access objects.
Questions:
Is this a known issue with accessIntervals or the Satellite Communications Toolbox?
How can I resolve or work around this error to compute access intervals?
Are there alternative methods to compute satellite-ground station access intervals if accessIntervals cannot be used?
Environment: Matlabonline Problem Description:
I am working on a MATLAB project involving the Satellite Communications Toolbox. My script uses the accessIntervals function to compute access intervals for satellites and ground stations. However, I consistently encounter the following error:
sql
Copy code
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row subscript and a variable subscript, as in t(rows,vars). To select variables, use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
Steps to Reproduce:
I created a satellite scenario with the following setup:matlabCopy codestartTime = datetime(2024, 1, 6, 23, 23, 0);
stopTime = startTime + hours(24);
sampleTime = 60;
sc = satelliteScenario(startTime, stopTime, sampleTime);
sat = walkerDelta(sc, 570e3 + 6378.14e3, 70, 720, 36, 1, ArgumentOfLatitude=15, Name="Starlink");
gs = groundStation(sc, "Name", "Test Station", "Latitude", -35.40139, "Longitude", 148.98167);
ac = access(sat, gs);
I attempted to call accessIntervals for the Access object:matlabCopy codeTest = accessIntervals(ac(1));
The error occurs for all Access objects (ac).
Debugging Steps Taken:
I confirmed the Access objects (ac) are valid and properly initialized:matlabCopy codeAccess Object 1:
Access with properties:
Sequence: [1 721]
LineWidth: 3
LineColor: [0.3922 0.8314 0.0745]
The error persists for all Access objects.
Questions:
Is this a known issue with accessIntervals or the Satellite Communications Toolbox?
How can I resolve or work around this error to compute access intervals?
Are there alternative methods to compute satellite-ground station access intervals if accessIntervals cannot be used?
Environment: Matlabonline accessintervals satellite toolbox satellite scenar, table indexing, error handling MATLAB Answers — New Questions
The lane markings appears at the right side of each road, but according to the official tutorial it should be at the road center.
the picture is below.I can’t find how to set the lane markings(the yellow lane in the picture) to the road center it needed. thanks for your warm help.the picture is below.I can’t find how to set the lane markings(the yellow lane in the picture) to the road center it needed. thanks for your warm help. the picture is below.I can’t find how to set the lane markings(the yellow lane in the picture) to the road center it needed. thanks for your warm help. driving scenario designer MATLAB Answers — New Questions
Edit Code Initialization under Mask editor
I am creating the mask for my simulink block and I need to add the Initiallization code to it. Unfortumatelly I can’t edit (add) code within the mask editor; it’s grayed and not editable, disabled.
How can I access this, and add the initialization code to it?
Thank you.I am creating the mask for my simulink block and I need to add the Initiallization code to it. Unfortumatelly I can’t edit (add) code within the mask editor; it’s grayed and not editable, disabled.
How can I access this, and add the initialization code to it?
Thank you. I am creating the mask for my simulink block and I need to add the Initiallization code to it. Unfortumatelly I can’t edit (add) code within the mask editor; it’s grayed and not editable, disabled.
How can I access this, and add the initialization code to it?
Thank you. initialization under mask editor MATLAB Answers — New Questions
Is it possible to generate code for cloud computing platforms (i.e. Azure, AWS)?
I would like to generate code from a Simulink model in a cloud computing platform. Is it possible?
Other option: is it possible to convert the generated C code from Simulink in other language (i.e. Python, Julia, R)?I would like to generate code from a Simulink model in a cloud computing platform. Is it possible?
Other option: is it possible to convert the generated C code from Simulink in other language (i.e. Python, Julia, R)? I would like to generate code from a Simulink model in a cloud computing platform. Is it possible?
Other option: is it possible to convert the generated C code from Simulink in other language (i.e. Python, Julia, R)? cloud, code generation, simulink, python MATLAB Answers — New Questions
Extract and sort size of matrix where in the cell
clc;clear;close all
im= [0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0];
cc=bwconncomp(im);
for i=1:cc.NumObjects
CC{i}=cc.PixelIdxList{i}
end
Size=zeros(1,cc.NumObjects);
for j=1:cc.NumObjects
Size(:,i)=size(cell2mat(CC(j)))
endclc;clear;close all
im= [0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0];
cc=bwconncomp(im);
for i=1:cc.NumObjects
CC{i}=cc.PixelIdxList{i}
end
Size=zeros(1,cc.NumObjects);
for j=1:cc.NumObjects
Size(:,i)=size(cell2mat(CC(j)))
end clc;clear;close all
im= [0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0];
cc=bwconncomp(im);
for i=1:cc.NumObjects
CC{i}=cc.PixelIdxList{i}
end
Size=zeros(1,cc.NumObjects);
for j=1:cc.NumObjects
Size(:,i)=size(cell2mat(CC(j)))
end for loop MATLAB Answers — New Questions
How to calculate the PSNR of video sequence?
Hi there,
I want to calculate the PSNR value between two videos. One video is original and another one is watermarked video. The watermarked video has some watermarked frame. I have calculated PSNR of each frame one at a time of both of the videos, and calsulate the average of it, but unfortunately I get the "Inf" value of PSNR.
Again, I have also tried to calculate the PSNR of exactly two videos. As a result, I got the PSNR of 40 dB. In fact, the result must be 99.99
Any help must be appreciated.
Thanks in advance.
The code I have written to calculate the PSNR of two idential videos
clc;
output_folder = ‘D:Matlab book and filesSLTAkiyo_frames_journal’;
vidObj1 = VideoReader(‘akiyo_cif_x264.mp4’);
vidObj2 = VideoReader(‘akiyo_cif_x264_Copy.mp4’);
EnumFrames=0;
Extframe = cell(1,300) ;
frame = cell(1,300) ;
numFrames1 = 0;
numFrames2 = 0;
while hasFrame(vidObj1)
F1 = readFrame(vidObj1);
numFrames1 = numFrames1 + 1;
frame{numFrames1} = F ;
numFrames1
while hasFrame(vidObj2)
F2 = readFrame(vidObj2);
numFrames2 = numFrames2 + 1;
Extframe{numFrames2}=F2;
end
numFrames2
for i= 1:300
Extframe{i}= getframe;
frame{i}= getframe;
fprintf ("The PSNR of frame %d = %.2f n", i , psnr(frame2im(Extframe{i}),frame2im(frame{i})))
end
OUTPUT
The PSNR of frame 1 = Inf
The PSNR of frame 2 = Inf
The PSNR of frame 3 = Inf
The PSNR of frame 4 = Inf
The PSNR of frame 5 = Inf
The PSNR of frame 6 = Inf
The PSNR of frame 7 = Inf
The PSNR of frame 8 = Inf
The PSNR of frame 9 = Inf
The PSNR of frame 10 = Inf
……………………………………..
………………………………………
……………………………………..
The PSNR of frame 300 = InfHi there,
I want to calculate the PSNR value between two videos. One video is original and another one is watermarked video. The watermarked video has some watermarked frame. I have calculated PSNR of each frame one at a time of both of the videos, and calsulate the average of it, but unfortunately I get the "Inf" value of PSNR.
Again, I have also tried to calculate the PSNR of exactly two videos. As a result, I got the PSNR of 40 dB. In fact, the result must be 99.99
Any help must be appreciated.
Thanks in advance.
The code I have written to calculate the PSNR of two idential videos
clc;
output_folder = ‘D:Matlab book and filesSLTAkiyo_frames_journal’;
vidObj1 = VideoReader(‘akiyo_cif_x264.mp4’);
vidObj2 = VideoReader(‘akiyo_cif_x264_Copy.mp4’);
EnumFrames=0;
Extframe = cell(1,300) ;
frame = cell(1,300) ;
numFrames1 = 0;
numFrames2 = 0;
while hasFrame(vidObj1)
F1 = readFrame(vidObj1);
numFrames1 = numFrames1 + 1;
frame{numFrames1} = F ;
numFrames1
while hasFrame(vidObj2)
F2 = readFrame(vidObj2);
numFrames2 = numFrames2 + 1;
Extframe{numFrames2}=F2;
end
numFrames2
for i= 1:300
Extframe{i}= getframe;
frame{i}= getframe;
fprintf ("The PSNR of frame %d = %.2f n", i , psnr(frame2im(Extframe{i}),frame2im(frame{i})))
end
OUTPUT
The PSNR of frame 1 = Inf
The PSNR of frame 2 = Inf
The PSNR of frame 3 = Inf
The PSNR of frame 4 = Inf
The PSNR of frame 5 = Inf
The PSNR of frame 6 = Inf
The PSNR of frame 7 = Inf
The PSNR of frame 8 = Inf
The PSNR of frame 9 = Inf
The PSNR of frame 10 = Inf
……………………………………..
………………………………………
……………………………………..
The PSNR of frame 300 = Inf Hi there,
I want to calculate the PSNR value between two videos. One video is original and another one is watermarked video. The watermarked video has some watermarked frame. I have calculated PSNR of each frame one at a time of both of the videos, and calsulate the average of it, but unfortunately I get the "Inf" value of PSNR.
Again, I have also tried to calculate the PSNR of exactly two videos. As a result, I got the PSNR of 40 dB. In fact, the result must be 99.99
Any help must be appreciated.
Thanks in advance.
The code I have written to calculate the PSNR of two idential videos
clc;
output_folder = ‘D:Matlab book and filesSLTAkiyo_frames_journal’;
vidObj1 = VideoReader(‘akiyo_cif_x264.mp4’);
vidObj2 = VideoReader(‘akiyo_cif_x264_Copy.mp4’);
EnumFrames=0;
Extframe = cell(1,300) ;
frame = cell(1,300) ;
numFrames1 = 0;
numFrames2 = 0;
while hasFrame(vidObj1)
F1 = readFrame(vidObj1);
numFrames1 = numFrames1 + 1;
frame{numFrames1} = F ;
numFrames1
while hasFrame(vidObj2)
F2 = readFrame(vidObj2);
numFrames2 = numFrames2 + 1;
Extframe{numFrames2}=F2;
end
numFrames2
for i= 1:300
Extframe{i}= getframe;
frame{i}= getframe;
fprintf ("The PSNR of frame %d = %.2f n", i , psnr(frame2im(Extframe{i}),frame2im(frame{i})))
end
OUTPUT
The PSNR of frame 1 = Inf
The PSNR of frame 2 = Inf
The PSNR of frame 3 = Inf
The PSNR of frame 4 = Inf
The PSNR of frame 5 = Inf
The PSNR of frame 6 = Inf
The PSNR of frame 7 = Inf
The PSNR of frame 8 = Inf
The PSNR of frame 9 = Inf
The PSNR of frame 10 = Inf
……………………………………..
………………………………………
……………………………………..
The PSNR of frame 300 = Inf video watermatrking, video processing, watermarking MATLAB Answers — New Questions
Why is my transformer training erroring out, with the following message “Error using trainnet (line 46)”
The full error message reads "Error using trainnet (line 46)
The number of mini-batch queue outputs (2) must match the number of network inputs plus
the number of network outputs (4)."
I’m using an arrayDatastore to pass the predictors (x2) and the targets(x2) to the transformer model. Both predictors have 410 features, one of the targets has 410 features and the other target is a scalar function.
Code to generate the dummy predictor and target data is pasted below:
%——————————————————————–
% data generation for encoder
numObs = 10;
seqLen = vocabSize;
x_enc = randi([1,10],[seqLen,numObs]);
y_enc = zeros(numObs,1);
for i = 1:numObs
idx = x_enc(1:2,i);
y_enc(i,:) = sum(x_enc(idx,i));
end
x_enc = num2cell(x_enc’,2);
y_enc = num2cell(y_enc)’;
x_1 = x_enc;
y_2 = y_enc’;
% data generation for decoder
x_series = randi([1,10],[seqLen,numObs]);
y_series = sin(rand([seqLen,numObs]));
x_dec = x_series(:,1:end)’;
y_dec = y_series(:,1:end)’;
x_dec = num2cell(x_dec,2); x_2 = x_dec;
y_dec = num2cell(y_dec,2); y_1 = y_dec;
cell_data = {}; cell_data = [cell_data x_1 x_2 y_1 y_2];
dstrain = arrayDatastore(cell_data,’OutputType’,’same’);
%——————————————————————-
cell_data is of the form:
cell_data
cell_data =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
If I were to use readall(dstrain) to read the datastore, I get the same format as cell_data:
fds = readall(dstrain)
fds =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
Finally, if I use minibatchqueue to create a minibatch of datastore ‘dstrain’, I get:
mbq = minibatchqueue(dstrain)
mbq =
minibatchqueue with 4 outputs and properties:
Mini-batch creation:
MiniBatchSize: 10
PartialMiniBatch: ‘return’
MiniBatchFcn: ‘collate’
PreprocessingEnvironment: ‘serial’
Outputs:
OutputCast: {‘single’ ‘single’ ‘single’ ‘single’}
OutputAsDlarray: [1 1 1 1]
MiniBatchFormat: {” ” ” ”}
OutputEnvironment: {‘auto’ ‘auto’ ‘auto’ ‘auto’}
As you can see, there are four outputs for the minibatch, which appears to contradict the original error message that there are only two minibatchqueue outputs
Also to confirm, i double checked the transformer input output structure:
net
net =
dlnetwork with properties:
Layers: [64×1 nnet.cnn.layer.Layer]
Connections: [1714×2 table]
Learnables: [110×3 table]
State: [0×3 table]
InputNames: {‘in_enc’ ‘in_dec’}
OutputNames: {‘decoder_out’ ‘fc_13’}
Initialized: 1
View summary with summary.
which shows two inputs and two outputs.
Could someone point me to the mistake I’m making here (likely with the datastore format) – it seems that during batching, the model is only choosing two of the cell columns from cell_data/dstrain for the input and output, rather than all four and its not clear why…thanks in advance for your help!
CGThe full error message reads "Error using trainnet (line 46)
The number of mini-batch queue outputs (2) must match the number of network inputs plus
the number of network outputs (4)."
I’m using an arrayDatastore to pass the predictors (x2) and the targets(x2) to the transformer model. Both predictors have 410 features, one of the targets has 410 features and the other target is a scalar function.
Code to generate the dummy predictor and target data is pasted below:
%——————————————————————–
% data generation for encoder
numObs = 10;
seqLen = vocabSize;
x_enc = randi([1,10],[seqLen,numObs]);
y_enc = zeros(numObs,1);
for i = 1:numObs
idx = x_enc(1:2,i);
y_enc(i,:) = sum(x_enc(idx,i));
end
x_enc = num2cell(x_enc’,2);
y_enc = num2cell(y_enc)’;
x_1 = x_enc;
y_2 = y_enc’;
% data generation for decoder
x_series = randi([1,10],[seqLen,numObs]);
y_series = sin(rand([seqLen,numObs]));
x_dec = x_series(:,1:end)’;
y_dec = y_series(:,1:end)’;
x_dec = num2cell(x_dec,2); x_2 = x_dec;
y_dec = num2cell(y_dec,2); y_1 = y_dec;
cell_data = {}; cell_data = [cell_data x_1 x_2 y_1 y_2];
dstrain = arrayDatastore(cell_data,’OutputType’,’same’);
%——————————————————————-
cell_data is of the form:
cell_data
cell_data =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
If I were to use readall(dstrain) to read the datastore, I get the same format as cell_data:
fds = readall(dstrain)
fds =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
Finally, if I use minibatchqueue to create a minibatch of datastore ‘dstrain’, I get:
mbq = minibatchqueue(dstrain)
mbq =
minibatchqueue with 4 outputs and properties:
Mini-batch creation:
MiniBatchSize: 10
PartialMiniBatch: ‘return’
MiniBatchFcn: ‘collate’
PreprocessingEnvironment: ‘serial’
Outputs:
OutputCast: {‘single’ ‘single’ ‘single’ ‘single’}
OutputAsDlarray: [1 1 1 1]
MiniBatchFormat: {” ” ” ”}
OutputEnvironment: {‘auto’ ‘auto’ ‘auto’ ‘auto’}
As you can see, there are four outputs for the minibatch, which appears to contradict the original error message that there are only two minibatchqueue outputs
Also to confirm, i double checked the transformer input output structure:
net
net =
dlnetwork with properties:
Layers: [64×1 nnet.cnn.layer.Layer]
Connections: [1714×2 table]
Learnables: [110×3 table]
State: [0×3 table]
InputNames: {‘in_enc’ ‘in_dec’}
OutputNames: {‘decoder_out’ ‘fc_13’}
Initialized: 1
View summary with summary.
which shows two inputs and two outputs.
Could someone point me to the mistake I’m making here (likely with the datastore format) – it seems that during batching, the model is only choosing two of the cell columns from cell_data/dstrain for the input and output, rather than all four and its not clear why…thanks in advance for your help!
CG The full error message reads "Error using trainnet (line 46)
The number of mini-batch queue outputs (2) must match the number of network inputs plus
the number of network outputs (4)."
I’m using an arrayDatastore to pass the predictors (x2) and the targets(x2) to the transformer model. Both predictors have 410 features, one of the targets has 410 features and the other target is a scalar function.
Code to generate the dummy predictor and target data is pasted below:
%——————————————————————–
% data generation for encoder
numObs = 10;
seqLen = vocabSize;
x_enc = randi([1,10],[seqLen,numObs]);
y_enc = zeros(numObs,1);
for i = 1:numObs
idx = x_enc(1:2,i);
y_enc(i,:) = sum(x_enc(idx,i));
end
x_enc = num2cell(x_enc’,2);
y_enc = num2cell(y_enc)’;
x_1 = x_enc;
y_2 = y_enc’;
% data generation for decoder
x_series = randi([1,10],[seqLen,numObs]);
y_series = sin(rand([seqLen,numObs]));
x_dec = x_series(:,1:end)’;
y_dec = y_series(:,1:end)’;
x_dec = num2cell(x_dec,2); x_2 = x_dec;
y_dec = num2cell(y_dec,2); y_1 = y_dec;
cell_data = {}; cell_data = [cell_data x_1 x_2 y_1 y_2];
dstrain = arrayDatastore(cell_data,’OutputType’,’same’);
%——————————————————————-
cell_data is of the form:
cell_data
cell_data =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
If I were to use readall(dstrain) to read the datastore, I get the same format as cell_data:
fds = readall(dstrain)
fds =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
Finally, if I use minibatchqueue to create a minibatch of datastore ‘dstrain’, I get:
mbq = minibatchqueue(dstrain)
mbq =
minibatchqueue with 4 outputs and properties:
Mini-batch creation:
MiniBatchSize: 10
PartialMiniBatch: ‘return’
MiniBatchFcn: ‘collate’
PreprocessingEnvironment: ‘serial’
Outputs:
OutputCast: {‘single’ ‘single’ ‘single’ ‘single’}
OutputAsDlarray: [1 1 1 1]
MiniBatchFormat: {” ” ” ”}
OutputEnvironment: {‘auto’ ‘auto’ ‘auto’ ‘auto’}
As you can see, there are four outputs for the minibatch, which appears to contradict the original error message that there are only two minibatchqueue outputs
Also to confirm, i double checked the transformer input output structure:
net
net =
dlnetwork with properties:
Layers: [64×1 nnet.cnn.layer.Layer]
Connections: [1714×2 table]
Learnables: [110×3 table]
State: [0×3 table]
InputNames: {‘in_enc’ ‘in_dec’}
OutputNames: {‘decoder_out’ ‘fc_13’}
Initialized: 1
View summary with summary.
which shows two inputs and two outputs.
Could someone point me to the mistake I’m making here (likely with the datastore format) – it seems that during batching, the model is only choosing two of the cell columns from cell_data/dstrain for the input and output, rather than all four and its not clear why…thanks in advance for your help!
CG deep learning, minibatch, datastore MATLAB Answers — New Questions
License manager causing more errors. So just making it test
Test to runTest to run Test to run cocktail party problem, blind source separation, independent components analysis, bss, ica, test MATLAB Answers — New Questions
Can I ‘initialize’ a handle object in such a way that isvalid(object) would return false?
I’m trying to initialize a variable (MyHandle) that I want to be a handle pointing to some object but which can’t currently be assigned to said object. I have code that needs to behave differently depending on if MyHandle is assigned or not yet and I haven’t found a good way to test if MyHandle has been assigned to a valid object or not.
The function ‘isvalid’ seems like the right choice to test this, however, isvalid throws the error "Incorrect number or types of inputs or outputs for function isvalid." when run on MyHandle in its unassigned state. I’ve tried different ways to initialize it like "handle([])" and "[]", but they all return that same error.
I’ve found some bandaid solutions like initializing MyHandle to an instance of some arbitrary handle subclass and then deleting that initialized object, or assigning MyHandle to be a value of type double and then using "isnumeric" as my test function instead of "isvalid," but I was wondering if there is a more "correct" way to do it for the sake of best practices.
Below is a sample class that recreates the behavior described above. To restate my question in terms of the class below: Is there an initialization for MyHandle I can use in the properties block that will allow IsHandleAssigned to return false before the first time AssignHandle is run with a valid handle and return true afterwards? OR is there a different function besides isvalid that I should be using in IsHandleAssigned to achieve that behavior?
classdef ExampleClass < handle
properties
MyHandle %Will be a handle pointing to an object of an arbitrary class
% MyHandle = handle([]) < This initialization returns an error
% MyHandle = [] < This initialization returns an error
% MyHandle = 0 < This works if I replace ‘isvalid’ with ‘isnumeric’
% but that seems like poor practice to do since it obfuscates the
% purpose of MyHandle
end
methods
function obj = AssignHandle(obj,handleIn)
%This method assigns the handle of whatever class it happens to
%be to my property.
obj.MyHandle = handleIn;
end
function HandleIsAssigned = IsHandleAssigned(obj)
%This method tests whether or not my handle was assigned. Is
%there a better function than isvalid to use?
HandleIsAssigned = isvalid(obj.MyHandle);
end
end
endI’m trying to initialize a variable (MyHandle) that I want to be a handle pointing to some object but which can’t currently be assigned to said object. I have code that needs to behave differently depending on if MyHandle is assigned or not yet and I haven’t found a good way to test if MyHandle has been assigned to a valid object or not.
The function ‘isvalid’ seems like the right choice to test this, however, isvalid throws the error "Incorrect number or types of inputs or outputs for function isvalid." when run on MyHandle in its unassigned state. I’ve tried different ways to initialize it like "handle([])" and "[]", but they all return that same error.
I’ve found some bandaid solutions like initializing MyHandle to an instance of some arbitrary handle subclass and then deleting that initialized object, or assigning MyHandle to be a value of type double and then using "isnumeric" as my test function instead of "isvalid," but I was wondering if there is a more "correct" way to do it for the sake of best practices.
Below is a sample class that recreates the behavior described above. To restate my question in terms of the class below: Is there an initialization for MyHandle I can use in the properties block that will allow IsHandleAssigned to return false before the first time AssignHandle is run with a valid handle and return true afterwards? OR is there a different function besides isvalid that I should be using in IsHandleAssigned to achieve that behavior?
classdef ExampleClass < handle
properties
MyHandle %Will be a handle pointing to an object of an arbitrary class
% MyHandle = handle([]) < This initialization returns an error
% MyHandle = [] < This initialization returns an error
% MyHandle = 0 < This works if I replace ‘isvalid’ with ‘isnumeric’
% but that seems like poor practice to do since it obfuscates the
% purpose of MyHandle
end
methods
function obj = AssignHandle(obj,handleIn)
%This method assigns the handle of whatever class it happens to
%be to my property.
obj.MyHandle = handleIn;
end
function HandleIsAssigned = IsHandleAssigned(obj)
%This method tests whether or not my handle was assigned. Is
%there a better function than isvalid to use?
HandleIsAssigned = isvalid(obj.MyHandle);
end
end
end I’m trying to initialize a variable (MyHandle) that I want to be a handle pointing to some object but which can’t currently be assigned to said object. I have code that needs to behave differently depending on if MyHandle is assigned or not yet and I haven’t found a good way to test if MyHandle has been assigned to a valid object or not.
The function ‘isvalid’ seems like the right choice to test this, however, isvalid throws the error "Incorrect number or types of inputs or outputs for function isvalid." when run on MyHandle in its unassigned state. I’ve tried different ways to initialize it like "handle([])" and "[]", but they all return that same error.
I’ve found some bandaid solutions like initializing MyHandle to an instance of some arbitrary handle subclass and then deleting that initialized object, or assigning MyHandle to be a value of type double and then using "isnumeric" as my test function instead of "isvalid," but I was wondering if there is a more "correct" way to do it for the sake of best practices.
Below is a sample class that recreates the behavior described above. To restate my question in terms of the class below: Is there an initialization for MyHandle I can use in the properties block that will allow IsHandleAssigned to return false before the first time AssignHandle is run with a valid handle and return true afterwards? OR is there a different function besides isvalid that I should be using in IsHandleAssigned to achieve that behavior?
classdef ExampleClass < handle
properties
MyHandle %Will be a handle pointing to an object of an arbitrary class
% MyHandle = handle([]) < This initialization returns an error
% MyHandle = [] < This initialization returns an error
% MyHandle = 0 < This works if I replace ‘isvalid’ with ‘isnumeric’
% but that seems like poor practice to do since it obfuscates the
% purpose of MyHandle
end
methods
function obj = AssignHandle(obj,handleIn)
%This method assigns the handle of whatever class it happens to
%be to my property.
obj.MyHandle = handleIn;
end
function HandleIsAssigned = IsHandleAssigned(obj)
%This method tests whether or not my handle was assigned. Is
%there a better function than isvalid to use?
HandleIsAssigned = isvalid(obj.MyHandle);
end
end
end handles MATLAB Answers — New Questions
getting group delay by differentiating phase of reflectance
Hi all
I am trying to calculate and draw the group delay of contradirectional bragg grating.
I already calculated the reflectance and got its phase as shown in the figure.
when I differentiate the phase i got unlogical spikes like that figure
while the correct plot is shown in Yariv book as the following figure (trace denoted by taw)
to differentiate i tried two functions diff and gradient and both gave me the same spikes (which is wrong). These are the lines i used in matlab:
Reflection=S11;
R=abs(Reflection).^2;
R_phase2=unwrap(angle(Reflection));
phase_lambda=lambda*1e9;
dphasedlambda1 =-phase_lambda.^2./(2*pi*c).*( gradient(R_phase2) ./ gradient(phase_lambda));
dphasedlambda2 =-phase_lambda(1:end-1).^2./(2*pi*c).*( diff(R_phase2) ./ diff(phase_lambda));
Any help with that problemHi all
I am trying to calculate and draw the group delay of contradirectional bragg grating.
I already calculated the reflectance and got its phase as shown in the figure.
when I differentiate the phase i got unlogical spikes like that figure
while the correct plot is shown in Yariv book as the following figure (trace denoted by taw)
to differentiate i tried two functions diff and gradient and both gave me the same spikes (which is wrong). These are the lines i used in matlab:
Reflection=S11;
R=abs(Reflection).^2;
R_phase2=unwrap(angle(Reflection));
phase_lambda=lambda*1e9;
dphasedlambda1 =-phase_lambda.^2./(2*pi*c).*( gradient(R_phase2) ./ gradient(phase_lambda));
dphasedlambda2 =-phase_lambda(1:end-1).^2./(2*pi*c).*( diff(R_phase2) ./ diff(phase_lambda));
Any help with that problem Hi all
I am trying to calculate and draw the group delay of contradirectional bragg grating.
I already calculated the reflectance and got its phase as shown in the figure.
when I differentiate the phase i got unlogical spikes like that figure
while the correct plot is shown in Yariv book as the following figure (trace denoted by taw)
to differentiate i tried two functions diff and gradient and both gave me the same spikes (which is wrong). These are the lines i used in matlab:
Reflection=S11;
R=abs(Reflection).^2;
R_phase2=unwrap(angle(Reflection));
phase_lambda=lambda*1e9;
dphasedlambda1 =-phase_lambda.^2./(2*pi*c).*( gradient(R_phase2) ./ gradient(phase_lambda));
dphasedlambda2 =-phase_lambda(1:end-1).^2./(2*pi*c).*( diff(R_phase2) ./ diff(phase_lambda));
Any help with that problem group delay, bragg, phase differentiation MATLAB Answers — New Questions
Dual fuel engine model
Is there some sort of dual fuel engine model already accessible? If not, are there any sort of forums or videos i could use as help to build Such a model. My simulink skills are very basic at the moment.Is there some sort of dual fuel engine model already accessible? If not, are there any sort of forums or videos i could use as help to build Such a model. My simulink skills are very basic at the moment. Is there some sort of dual fuel engine model already accessible? If not, are there any sort of forums or videos i could use as help to build Such a model. My simulink skills are very basic at the moment. dual fuel, lpg, engine MATLAB Answers — New Questions
Generate signal according to the the rising edges of two pulse generators in simulink.
Assume there are two pulses A and B with arbitrary periods and pulse widths.
I want to use existing popular blocks(without MATLAB Function) to realize such functionality–
it sets the output as 1 at the rising edge of A if B=0 and resets the output to 0 at the rising edge of B.
I have been thinking for a whole day without a good solution.
Anyone please help me on that.Assume there are two pulses A and B with arbitrary periods and pulse widths.
I want to use existing popular blocks(without MATLAB Function) to realize such functionality–
it sets the output as 1 at the rising edge of A if B=0 and resets the output to 0 at the rising edge of B.
I have been thinking for a whole day without a good solution.
Anyone please help me on that. Assume there are two pulses A and B with arbitrary periods and pulse widths.
I want to use existing popular blocks(without MATLAB Function) to realize such functionality–
it sets the output as 1 at the rising edge of A if B=0 and resets the output to 0 at the rising edge of B.
I have been thinking for a whole day without a good solution.
Anyone please help me on that. signal processing MATLAB Answers — New Questions
Find real valued parameters of a complex equation/model by using optimization or curve fitting.
I am trying to replicate finding the optimized parameters of a Lorentz model defined in the paper titled, "EXTRACTION OF EFFECTIVE METAMATERIAL PARAMETERS BY PARAMETER FITTING OF DISPERSIVE MODEL" (linked here). I’ve provided the equation and table of paramters below:
I’ve tried the curve fitting tool and get different results especially when I try to change the bounds. Sometimes I am able to get paramters that match the table above but my confidence in repeatbility isn’t high. I’ve also tried scripting code to use the "fittype", "lsqnonlin", or "fminsearch" but also get different answers as well. In the code below, I’m comparing the fit to the real and imaginary parts of the Lorentz model. The fit to the real data is way off and even though the fit to the imaginary values looks qualitatively good. For the fit to the imaginary part, I get different values for the estimated parameters compared to what’s reported in the paper.
%% Parameters in Table
e_inf = 1.62;
wp = 2*pi*14.63*1e9; % GHz
vc = 30.69*1e6; %MHz
mu_s = 1.26;
mu_inf = 1.12;
wo = 2*pi*9.67*1e9; % GHz
delta = 1.24*1e9; % GHz
%%
fo = [7:0.01:12].*1e9; % GHz
w = 2*pi*fo;
mu_eff = mu_inf + ((mu_s – mu_inf)*wo.^2)./(wo.^2 + 1i*w*delta – w.^2); % equation in paper / Lorentz model
real_mu_eff = real(mu_eff);
imag_mu_eff = imag(mu_eff);
x = fo;
y = real_mu_eff;
x2 = fo;
y2 = imag_mu_eff;
myfittype = fittype("real(a+((b-a)*(2*pi*1e9*c).^2)./((2*pi*1e9*c).^2+1i*2*pi*x*d*1e9-x.^2))",…
dependent="y",independent="x",…
coefficients=["a" "b" "c" "d"])
myfit = fit(x’,y’,myfittype)
figure
plot(myfit,x,y)
myfittype2 = fittype("imag(a2+((b2-a2)*(2*pi*1e9*c2).^2)./((2*pi*1e9*c2).^2+1i*2*pi*x2*d2*1e9-x2.^2))",…
dependent="y2",independent="x2",…
coefficients=["a2" "b2" "c2" "d2"])
myfit2 = fit(x2′,y2′,myfittype2)
figure
plot(myfit2,x2,y2)
The results I was expecting were: a=1.12, b=1.26, c=9.67, and d=1.24. I ‘ve atttached my attempts with using "lsqnonlin", "lsqcurvefit", and "fminsearch"; however I didn’t have success in using those methods either. What is best way to find the parameters of the Lorentz model to get the values in the table above?I am trying to replicate finding the optimized parameters of a Lorentz model defined in the paper titled, "EXTRACTION OF EFFECTIVE METAMATERIAL PARAMETERS BY PARAMETER FITTING OF DISPERSIVE MODEL" (linked here). I’ve provided the equation and table of paramters below:
I’ve tried the curve fitting tool and get different results especially when I try to change the bounds. Sometimes I am able to get paramters that match the table above but my confidence in repeatbility isn’t high. I’ve also tried scripting code to use the "fittype", "lsqnonlin", or "fminsearch" but also get different answers as well. In the code below, I’m comparing the fit to the real and imaginary parts of the Lorentz model. The fit to the real data is way off and even though the fit to the imaginary values looks qualitatively good. For the fit to the imaginary part, I get different values for the estimated parameters compared to what’s reported in the paper.
%% Parameters in Table
e_inf = 1.62;
wp = 2*pi*14.63*1e9; % GHz
vc = 30.69*1e6; %MHz
mu_s = 1.26;
mu_inf = 1.12;
wo = 2*pi*9.67*1e9; % GHz
delta = 1.24*1e9; % GHz
%%
fo = [7:0.01:12].*1e9; % GHz
w = 2*pi*fo;
mu_eff = mu_inf + ((mu_s – mu_inf)*wo.^2)./(wo.^2 + 1i*w*delta – w.^2); % equation in paper / Lorentz model
real_mu_eff = real(mu_eff);
imag_mu_eff = imag(mu_eff);
x = fo;
y = real_mu_eff;
x2 = fo;
y2 = imag_mu_eff;
myfittype = fittype("real(a+((b-a)*(2*pi*1e9*c).^2)./((2*pi*1e9*c).^2+1i*2*pi*x*d*1e9-x.^2))",…
dependent="y",independent="x",…
coefficients=["a" "b" "c" "d"])
myfit = fit(x’,y’,myfittype)
figure
plot(myfit,x,y)
myfittype2 = fittype("imag(a2+((b2-a2)*(2*pi*1e9*c2).^2)./((2*pi*1e9*c2).^2+1i*2*pi*x2*d2*1e9-x2.^2))",…
dependent="y2",independent="x2",…
coefficients=["a2" "b2" "c2" "d2"])
myfit2 = fit(x2′,y2′,myfittype2)
figure
plot(myfit2,x2,y2)
The results I was expecting were: a=1.12, b=1.26, c=9.67, and d=1.24. I ‘ve atttached my attempts with using "lsqnonlin", "lsqcurvefit", and "fminsearch"; however I didn’t have success in using those methods either. What is best way to find the parameters of the Lorentz model to get the values in the table above? I am trying to replicate finding the optimized parameters of a Lorentz model defined in the paper titled, "EXTRACTION OF EFFECTIVE METAMATERIAL PARAMETERS BY PARAMETER FITTING OF DISPERSIVE MODEL" (linked here). I’ve provided the equation and table of paramters below:
I’ve tried the curve fitting tool and get different results especially when I try to change the bounds. Sometimes I am able to get paramters that match the table above but my confidence in repeatbility isn’t high. I’ve also tried scripting code to use the "fittype", "lsqnonlin", or "fminsearch" but also get different answers as well. In the code below, I’m comparing the fit to the real and imaginary parts of the Lorentz model. The fit to the real data is way off and even though the fit to the imaginary values looks qualitatively good. For the fit to the imaginary part, I get different values for the estimated parameters compared to what’s reported in the paper.
%% Parameters in Table
e_inf = 1.62;
wp = 2*pi*14.63*1e9; % GHz
vc = 30.69*1e6; %MHz
mu_s = 1.26;
mu_inf = 1.12;
wo = 2*pi*9.67*1e9; % GHz
delta = 1.24*1e9; % GHz
%%
fo = [7:0.01:12].*1e9; % GHz
w = 2*pi*fo;
mu_eff = mu_inf + ((mu_s – mu_inf)*wo.^2)./(wo.^2 + 1i*w*delta – w.^2); % equation in paper / Lorentz model
real_mu_eff = real(mu_eff);
imag_mu_eff = imag(mu_eff);
x = fo;
y = real_mu_eff;
x2 = fo;
y2 = imag_mu_eff;
myfittype = fittype("real(a+((b-a)*(2*pi*1e9*c).^2)./((2*pi*1e9*c).^2+1i*2*pi*x*d*1e9-x.^2))",…
dependent="y",independent="x",…
coefficients=["a" "b" "c" "d"])
myfit = fit(x’,y’,myfittype)
figure
plot(myfit,x,y)
myfittype2 = fittype("imag(a2+((b2-a2)*(2*pi*1e9*c2).^2)./((2*pi*1e9*c2).^2+1i*2*pi*x2*d2*1e9-x2.^2))",…
dependent="y2",independent="x2",…
coefficients=["a2" "b2" "c2" "d2"])
myfit2 = fit(x2′,y2′,myfittype2)
figure
plot(myfit2,x2,y2)
The results I was expecting were: a=1.12, b=1.26, c=9.67, and d=1.24. I ‘ve atttached my attempts with using "lsqnonlin", "lsqcurvefit", and "fminsearch"; however I didn’t have success in using those methods either. What is best way to find the parameters of the Lorentz model to get the values in the table above? optimization, curve fitting, physics, electrical, material characterization, debye, lorentz MATLAB Answers — New Questions
How can I programmatically set uigetfiles() display mode and file sort order?
I use Matlab 2023b to create applications in Linux and Windows. The function uigetfiles() default behavior in Windows is to display files w/details, in reverse chronological order, which is what I want. Conversely, in Linux, it displays the same files as a list in chronological order. Users can use the UI tools to change default characteristics, but I’d like to set them programatically before the UI is displayed. Is there a way to control the display mode (icon, list, detail) and file order (alphabetical, chronological, etc?), or is there an alternative function that does this?I use Matlab 2023b to create applications in Linux and Windows. The function uigetfiles() default behavior in Windows is to display files w/details, in reverse chronological order, which is what I want. Conversely, in Linux, it displays the same files as a list in chronological order. Users can use the UI tools to change default characteristics, but I’d like to set them programatically before the UI is displayed. Is there a way to control the display mode (icon, list, detail) and file order (alphabetical, chronological, etc?), or is there an alternative function that does this? I use Matlab 2023b to create applications in Linux and Windows. The function uigetfiles() default behavior in Windows is to display files w/details, in reverse chronological order, which is what I want. Conversely, in Linux, it displays the same files as a list in chronological order. Users can use the UI tools to change default characteristics, but I’d like to set them programatically before the UI is displayed. Is there a way to control the display mode (icon, list, detail) and file order (alphabetical, chronological, etc?), or is there an alternative function that does this? display mode, sort order, uigetfile MATLAB Answers — New Questions
MPT3 installation issue on a mac M1 pro platform
Hello everyone,
I’m a user of MPT3(multi-parametric toolbox 3), and my computer is a Mac M1 Pro, my Matlab version is 2024b.
When I installed the MPT3 on my computer, the following issue happens:
Error using tbxmanager>main_install (line 468)
Toolbox "cddmex" is not available for your platform.
Error using tbxmanager (line 150)
Cannot continue, see message above.
Error in install_mpt3 (line 55)
tbxmanager install mpt mptdoc cddmex fourier glpkmex hysdel lcp sedumi yalmip
^^^^^^^^^^
Actually, this does not only happen for tool "cddmex", other toolboxes, including "fourier glpkmex hysdel lcp sedumi", also has this issue.
However, when I installed it for my matlab2021b, it was successful.
Does anyone know the way to fix it?Hello everyone,
I’m a user of MPT3(multi-parametric toolbox 3), and my computer is a Mac M1 Pro, my Matlab version is 2024b.
When I installed the MPT3 on my computer, the following issue happens:
Error using tbxmanager>main_install (line 468)
Toolbox "cddmex" is not available for your platform.
Error using tbxmanager (line 150)
Cannot continue, see message above.
Error in install_mpt3 (line 55)
tbxmanager install mpt mptdoc cddmex fourier glpkmex hysdel lcp sedumi yalmip
^^^^^^^^^^
Actually, this does not only happen for tool "cddmex", other toolboxes, including "fourier glpkmex hysdel lcp sedumi", also has this issue.
However, when I installed it for my matlab2021b, it was successful.
Does anyone know the way to fix it? Hello everyone,
I’m a user of MPT3(multi-parametric toolbox 3), and my computer is a Mac M1 Pro, my Matlab version is 2024b.
When I installed the MPT3 on my computer, the following issue happens:
Error using tbxmanager>main_install (line 468)
Toolbox "cddmex" is not available for your platform.
Error using tbxmanager (line 150)
Cannot continue, see message above.
Error in install_mpt3 (line 55)
tbxmanager install mpt mptdoc cddmex fourier glpkmex hysdel lcp sedumi yalmip
^^^^^^^^^^
Actually, this does not only happen for tool "cddmex", other toolboxes, including "fourier glpkmex hysdel lcp sedumi", also has this issue.
However, when I installed it for my matlab2021b, it was successful.
Does anyone know the way to fix it? mpt3, toolbox, control, optimization MATLAB Answers — New Questions
Interpretation of warning message from fitglme: “Warning: Final linear predictor from PL iterations is not feasible.”
Hi all,
I’m looking to understand the meaning of a warning message returned by the fitglme function. That warning is "Warning: Final linear predictor from PL iterations is not feasible". I see that here have been two other posts on these forums with the same question but have yet to receive any response, i.e. here and here.
Thank you for your assistance,
JMDHi all,
I’m looking to understand the meaning of a warning message returned by the fitglme function. That warning is "Warning: Final linear predictor from PL iterations is not feasible". I see that here have been two other posts on these forums with the same question but have yet to receive any response, i.e. here and here.
Thank you for your assistance,
JMD Hi all,
I’m looking to understand the meaning of a warning message returned by the fitglme function. That warning is "Warning: Final linear predictor from PL iterations is not feasible". I see that here have been two other posts on these forums with the same question but have yet to receive any response, i.e. here and here.
Thank you for your assistance,
JMD fitglme, mixed effects, warning MATLAB Answers — New Questions