Month: January 2025
programing in Simulink a lamp
i need the lamp to display different color when it gets certain value from the matlab function. i add another Matlab Function to program the lamp but i am not sure if that such a thing to exist.
this is simulink. Here is my code that is in the Matlab Function to program the lamp as you see how i connect the lamp to the function. the code below is the code inside the matlab function. i am not even sure if my code is right at all.
function lampStates = caution(distance)
lampState1.Value = ( distance >= 0.0) && ( distance <= 0.5);
lampState2.Value = ( distance == 0.5);
lampState3.Value = ( distance == 1.5);
lampState4.Value = ( distance == 2.5);
lampState5.Value = ( distance >= 2.5);
if ( distance >= 0.0) && ( distance <= 0.5)
lampState1.Color = [254 51 10];
elseif ( distance == 0.5)
lampState2.Color = [237 177 32];
elseif ( distance == 1.5)
lampState3.Color = [100 212 19];
elseif ( distance == 2.5)
lampState4.Color = [237 177 32];
elseif ( distance >= 2.5)
lampState5.Color = [254 51 10];
end
lampStates = [lampState1 lampState2 lampState3 lampState4 lampState5];i need the lamp to display different color when it gets certain value from the matlab function. i add another Matlab Function to program the lamp but i am not sure if that such a thing to exist.
this is simulink. Here is my code that is in the Matlab Function to program the lamp as you see how i connect the lamp to the function. the code below is the code inside the matlab function. i am not even sure if my code is right at all.
function lampStates = caution(distance)
lampState1.Value = ( distance >= 0.0) && ( distance <= 0.5);
lampState2.Value = ( distance == 0.5);
lampState3.Value = ( distance == 1.5);
lampState4.Value = ( distance == 2.5);
lampState5.Value = ( distance >= 2.5);
if ( distance >= 0.0) && ( distance <= 0.5)
lampState1.Color = [254 51 10];
elseif ( distance == 0.5)
lampState2.Color = [237 177 32];
elseif ( distance == 1.5)
lampState3.Color = [100 212 19];
elseif ( distance == 2.5)
lampState4.Color = [237 177 32];
elseif ( distance >= 2.5)
lampState5.Color = [254 51 10];
end
lampStates = [lampState1 lampState2 lampState3 lampState4 lampState5]; i need the lamp to display different color when it gets certain value from the matlab function. i add another Matlab Function to program the lamp but i am not sure if that such a thing to exist.
this is simulink. Here is my code that is in the Matlab Function to program the lamp as you see how i connect the lamp to the function. the code below is the code inside the matlab function. i am not even sure if my code is right at all.
function lampStates = caution(distance)
lampState1.Value = ( distance >= 0.0) && ( distance <= 0.5);
lampState2.Value = ( distance == 0.5);
lampState3.Value = ( distance == 1.5);
lampState4.Value = ( distance == 2.5);
lampState5.Value = ( distance >= 2.5);
if ( distance >= 0.0) && ( distance <= 0.5)
lampState1.Color = [254 51 10];
elseif ( distance == 0.5)
lampState2.Color = [237 177 32];
elseif ( distance == 1.5)
lampState3.Color = [100 212 19];
elseif ( distance == 2.5)
lampState4.Color = [237 177 32];
elseif ( distance >= 2.5)
lampState5.Color = [254 51 10];
end
lampStates = [lampState1 lampState2 lampState3 lampState4 lampState5]; display different color lamp MATLAB Answers — New Questions
LAG VALUE OF A VARIABLE
Hello,
I want to have a lag value of variable X (PANEL of nature), but since Matlab does not accept different matrix size variables, what should I do. Variable is 4100*1 and lag of it is 3936*1.Hello,
I want to have a lag value of variable X (PANEL of nature), but since Matlab does not accept different matrix size variables, what should I do. Variable is 4100*1 and lag of it is 3936*1. Hello,
I want to have a lag value of variable X (PANEL of nature), but since Matlab does not accept different matrix size variables, what should I do. Variable is 4100*1 and lag of it is 3936*1. lag values MATLAB Answers — New Questions
syms error, cannot use syms command
I am having an issue using the syms command:
syms x(t) y(t)
getting the following error:
Error using assignin
Invalid variable name "x(t)" in ASSIGNIN.
Error in syms (line 56)
assignin(‘caller’,varargin{i},sym(varargin{i}));
Error in Untitled (line 1)
syms x(t) y(t)
I am tried the following solution but I can not solve my problem"
which -all syms
C:Program FilesMATLABR2018btoolboxmaplesyms.m
My Matlab ver: R2018b
On my system Maple 2018 was installed at: C:Program FilesMaple 2018I am having an issue using the syms command:
syms x(t) y(t)
getting the following error:
Error using assignin
Invalid variable name "x(t)" in ASSIGNIN.
Error in syms (line 56)
assignin(‘caller’,varargin{i},sym(varargin{i}));
Error in Untitled (line 1)
syms x(t) y(t)
I am tried the following solution but I can not solve my problem"
which -all syms
C:Program FilesMATLABR2018btoolboxmaplesyms.m
My Matlab ver: R2018b
On my system Maple 2018 was installed at: C:Program FilesMaple 2018 I am having an issue using the syms command:
syms x(t) y(t)
getting the following error:
Error using assignin
Invalid variable name "x(t)" in ASSIGNIN.
Error in syms (line 56)
assignin(‘caller’,varargin{i},sym(varargin{i}));
Error in Untitled (line 1)
syms x(t) y(t)
I am tried the following solution but I can not solve my problem"
which -all syms
C:Program FilesMATLABR2018btoolboxmaplesyms.m
My Matlab ver: R2018b
On my system Maple 2018 was installed at: C:Program FilesMaple 2018 syms error MATLAB Answers — New Questions
Invalid operand. Variables of type “sym” cannot be combined with other models.
Hello, how can I resolve the error "Invalid operand. Variables of type "sym" cannot be combined with other models." in this code. Separately if it works for me. Thanks
d=5;%sobreoscilacion
tp=4; %tiempo pico
k=100;
syms e w
ecA=((-e*pi)/sqrt(1-e^2))-log(d)== 0;
e= vpa(solve(ecA,e)); %valor epsilon
ecB=(pi/(w*(sqrt(1-e^2))))-tp==0;
w= vpa(solve(ecB,w)); %valor ohmega
%%%%
s=tf(‘s’);
Q=((k*(w)^2)/(s^2+2*e+s+(w)^2))*exp(-tp*s);
Q_apro=pade(Q,1);Hello, how can I resolve the error "Invalid operand. Variables of type "sym" cannot be combined with other models." in this code. Separately if it works for me. Thanks
d=5;%sobreoscilacion
tp=4; %tiempo pico
k=100;
syms e w
ecA=((-e*pi)/sqrt(1-e^2))-log(d)== 0;
e= vpa(solve(ecA,e)); %valor epsilon
ecB=(pi/(w*(sqrt(1-e^2))))-tp==0;
w= vpa(solve(ecB,w)); %valor ohmega
%%%%
s=tf(‘s’);
Q=((k*(w)^2)/(s^2+2*e+s+(w)^2))*exp(-tp*s);
Q_apro=pade(Q,1); Hello, how can I resolve the error "Invalid operand. Variables of type "sym" cannot be combined with other models." in this code. Separately if it works for me. Thanks
d=5;%sobreoscilacion
tp=4; %tiempo pico
k=100;
syms e w
ecA=((-e*pi)/sqrt(1-e^2))-log(d)== 0;
e= vpa(solve(ecA,e)); %valor epsilon
ecB=(pi/(w*(sqrt(1-e^2))))-tp==0;
w= vpa(solve(ecB,w)); %valor ohmega
%%%%
s=tf(‘s’);
Q=((k*(w)^2)/(s^2+2*e+s+(w)^2))*exp(-tp*s);
Q_apro=pade(Q,1); syms, sym MATLAB Answers — New Questions
figure does not print or print preview
When I try print a figure or even print preview the figure I get the error below. This happens with 2019b version. Thanks.
rror using printopt
Too many input arguments.
Error in matlab.graphics.internal.mlprintjob
Error in printjob (line 22)
pj = matlab.graphics.internal.mlprintjob;
Error in print>LocalCreatePrintJob (line 102)
pj = printjob([handles{:}]);
Error in print (line 38)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
Error in printdlg (line 63)
print(Fig, ‘-v’);
Error while evaluating Menu Callback.When I try print a figure or even print preview the figure I get the error below. This happens with 2019b version. Thanks.
rror using printopt
Too many input arguments.
Error in matlab.graphics.internal.mlprintjob
Error in printjob (line 22)
pj = matlab.graphics.internal.mlprintjob;
Error in print>LocalCreatePrintJob (line 102)
pj = printjob([handles{:}]);
Error in print (line 38)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
Error in printdlg (line 63)
print(Fig, ‘-v’);
Error while evaluating Menu Callback. When I try print a figure or even print preview the figure I get the error below. This happens with 2019b version. Thanks.
rror using printopt
Too many input arguments.
Error in matlab.graphics.internal.mlprintjob
Error in printjob (line 22)
pj = matlab.graphics.internal.mlprintjob;
Error in print>LocalCreatePrintJob (line 102)
pj = printjob([handles{:}]);
Error in print (line 38)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
Error in printdlg (line 63)
print(Fig, ‘-v’);
Error while evaluating Menu Callback. print MATLAB Answers — New Questions
select only rows and not columns
Does anybody knows how to select only rows and not columns? I’m trying to select all the first values of each column, is that possible?Does anybody knows how to select only rows and not columns? I’m trying to select all the first values of each column, is that possible? Does anybody knows how to select only rows and not columns? I’m trying to select all the first values of each column, is that possible? rows, columns, matrix MATLAB Answers — New Questions
SIL on autosar composition, Different Types error
I have an autsoar architecture model(autosar composition).
At first I created a test harness on the architecture model and wanted to make sil test. I got error it is not supported I shall set the SimulationMode of architecture model to normal and the SimulationMode of the autosar compome below to the SIL. I did it
Then I got the error Different types as below shown
I follow another way as mathwork proposal, Testing AUTOSAR Compositions
At the end I got the same error Different types with no any helpful info what going wrong :(I have an autsoar architecture model(autosar composition).
At first I created a test harness on the architecture model and wanted to make sil test. I got error it is not supported I shall set the SimulationMode of architecture model to normal and the SimulationMode of the autosar compome below to the SIL. I did it
Then I got the error Different types as below shown
I follow another way as mathwork proposal, Testing AUTOSAR Compositions
At the end I got the same error Different types with no any helpful info what going wrong 🙁 I have an autsoar architecture model(autosar composition).
At first I created a test harness on the architecture model and wanted to make sil test. I got error it is not supported I shall set the SimulationMode of architecture model to normal and the SimulationMode of the autosar compome below to the SIL. I did it
Then I got the error Different types as below shown
I follow another way as mathwork proposal, Testing AUTOSAR Compositions
At the end I got the same error Different types with no any helpful info what going wrong 🙁 autosar sil test MATLAB Answers — New Questions
Unterminated quote in @-file: n” error when appending pdfs
error when appending pdfserror when appending pdfs error when appending pdfs append pdf error MATLAB Answers — New Questions
How to add extra text to plot legend?
Hi, guys
Let us suppose that I have the following simple code:
clc; clear all; close all;
x = linspace(0, 2*pi, 100);
figure
hold on;grid on; box on;
plot(x,sin(x));
plot(x, cos(x));
plot(x, tan(x));
axis([0 2*pi -4 4]);
legend(‘sin’, ‘cos’, ‘tan’);
My goal is to add some extra text in the legend box as shown in the following image example (image modified with gimp):
Can you help me to codify this task?Hi, guys
Let us suppose that I have the following simple code:
clc; clear all; close all;
x = linspace(0, 2*pi, 100);
figure
hold on;grid on; box on;
plot(x,sin(x));
plot(x, cos(x));
plot(x, tan(x));
axis([0 2*pi -4 4]);
legend(‘sin’, ‘cos’, ‘tan’);
My goal is to add some extra text in the legend box as shown in the following image example (image modified with gimp):
Can you help me to codify this task? Hi, guys
Let us suppose that I have the following simple code:
clc; clear all; close all;
x = linspace(0, 2*pi, 100);
figure
hold on;grid on; box on;
plot(x,sin(x));
plot(x, cos(x));
plot(x, tan(x));
axis([0 2*pi -4 4]);
legend(‘sin’, ‘cos’, ‘tan’);
My goal is to add some extra text in the legend box as shown in the following image example (image modified with gimp):
Can you help me to codify this task? legend, text, plots MATLAB Answers — New Questions
I need to be able to limit in a platform(aircraft), the line-of-sight “MinElevationAngle” in a satellite scenario
"MinElevationAngle" is found in the ground station object to only have line-of-sight satellites above a mask angle. How can we do that for an aircraft?"MinElevationAngle" is found in the ground station object to only have line-of-sight satellites above a mask angle. How can we do that for an aircraft? "MinElevationAngle" is found in the ground station object to only have line-of-sight satellites above a mask angle. How can we do that for an aircraft? satellitescenario, platform MATLAB Answers — New Questions
Camera characterization gives “symetrical results”?
I downloaded the code from :
https://www.mathworks.com/matlabcentral/fileexchange/40640-computational-colour-science-using-matlab-2e?s_tid=srchtitle
I modified the code for my purposes. Please find all the attached elements to run the script at your end. What I don’t understand is how the final resulting image looks exactly like the starting image? I understand how the 3rd degree polynomial is calculated but there must be something I miss in applying the M3 matrix back to my original image?
Any help is appreciated.I downloaded the code from :
https://www.mathworks.com/matlabcentral/fileexchange/40640-computational-colour-science-using-matlab-2e?s_tid=srchtitle
I modified the code for my purposes. Please find all the attached elements to run the script at your end. What I don’t understand is how the final resulting image looks exactly like the starting image? I understand how the 3rd degree polynomial is calculated but there must be something I miss in applying the M3 matrix back to my original image?
Any help is appreciated. I downloaded the code from :
https://www.mathworks.com/matlabcentral/fileexchange/40640-computational-colour-science-using-matlab-2e?s_tid=srchtitle
I modified the code for my purposes. Please find all the attached elements to run the script at your end. What I don’t understand is how the final resulting image looks exactly like the starting image? I understand how the 3rd degree polynomial is calculated but there must be something I miss in applying the M3 matrix back to my original image?
Any help is appreciated. camera characterization, xyz to rgb, polynomial, color management MATLAB Answers — New Questions
Short Pause doesn’t come back
Using App Designer I was running my program with no breakpoints set.
Suddenly it stopped running in a place it shouldn’t so I broke out to see what’s going on and found this:
My understanding is that the open arrow signifies a place where the code has called a routine and not come back yet.
So what’s wrong with this pause this time, after it ran fine 9 times in the last 10 seconds or so?Using App Designer I was running my program with no breakpoints set.
Suddenly it stopped running in a place it shouldn’t so I broke out to see what’s going on and found this:
My understanding is that the open arrow signifies a place where the code has called a routine and not come back yet.
So what’s wrong with this pause this time, after it ran fine 9 times in the last 10 seconds or so? Using App Designer I was running my program with no breakpoints set.
Suddenly it stopped running in a place it shouldn’t so I broke out to see what’s going on and found this:
My understanding is that the open arrow signifies a place where the code has called a routine and not come back yet.
So what’s wrong with this pause this time, after it ran fine 9 times in the last 10 seconds or so? pause MATLAB Answers — New Questions
Aardvark Communications Issue – Error stating no driver installed
I’ve installed the Aardvark USB drivers from Total Phase and installed the add on support package for the instrument toolbox but am still getting a driver error in Matlab.
Verified it is installed and I can connect to it using the total phase software tools.I’ve installed the Aardvark USB drivers from Total Phase and installed the add on support package for the instrument toolbox but am still getting a driver error in Matlab.
Verified it is installed and I can connect to it using the total phase software tools. I’ve installed the Aardvark USB drivers from Total Phase and installed the add on support package for the instrument toolbox but am still getting a driver error in Matlab.
Verified it is installed and I can connect to it using the total phase software tools. aardvark MATLAB Answers — New Questions
Variable Names not being read into uitable using readmatrix
Hi, I am trying to read a csv files into a uitable and am having problems reading the variable names in. The csv was saved using writetable and the first few lines are here:
Idx,pos,sep1,sep2,avgsep,deltaPix
1,101.1,1799.918,1868.078,1833.998,0.769999999999
2,101.2,1801.527,1868.695,1835.111,1.88299999999
3,101.3,1802.028,1869.09,1835.559,2.3309999999
4,101.4,1801.645,1869.739,1835.692,2.46399999999
5,101.5,1802.023,1869.453,1835.738,2.50999999999
This is my code to read the file :
table=app.UItable;
C=readtable(fullpath,’VariableNamingRule’,’preserve’,’FileType’,’text’);
C=table2array(C); % Wasn’t sure if I needed this
opts = detectImportOptions(fullpath)
opts.VariableNames
ReportMessage(app,’Opened Successfully’)
table.Data=C;
Its not reading in the variable name
The opts.variablenames is showing the variable names are present
ans =
1×6 cell array
{‘Idx’} {‘pos’} {‘sep1’} {‘sep2’} {‘avgsep’} {‘deltaPix’}
and opts is:
opts =
DelimitedTextImportOptions with properties:
Format Properties:
Delimiter: {‘,’}
Whitespace: ‘bt ‘
LineEnding: {‘n’ ‘r’ ‘rn’}
CommentStyle: {}
ConsecutiveDelimitersRule: ‘split’
LeadingDelimitersRule: ‘keep’
TrailingDelimitersRule: ‘ignore’
EmptyLineRule: ‘skip’
Encoding: ‘UTF-8’
Replacement Properties:
MissingRule: ‘fill’
ImportErrorRule: ‘fill’
ExtraColumnsRule: ‘addvars’
Variable Import Properties: Set types by name using setvartype
VariableNames: {‘Idx’, ‘pos’, ‘sep1’ … and 3 more}
VariableTypes: {‘double’, ‘double’, ‘double’ … and 3 more}
SelectedVariableNames: {‘Idx’, ‘pos’, ‘sep1’ … and 3 more}
VariableOptions: Show all 6 VariableOptions
Access VariableOptions sub-properties using setvaropts/getvaropts
VariableNamingRule: ‘modify’
Any reason why the variable names aren’t being populated into the uitable?
ThanksHi, I am trying to read a csv files into a uitable and am having problems reading the variable names in. The csv was saved using writetable and the first few lines are here:
Idx,pos,sep1,sep2,avgsep,deltaPix
1,101.1,1799.918,1868.078,1833.998,0.769999999999
2,101.2,1801.527,1868.695,1835.111,1.88299999999
3,101.3,1802.028,1869.09,1835.559,2.3309999999
4,101.4,1801.645,1869.739,1835.692,2.46399999999
5,101.5,1802.023,1869.453,1835.738,2.50999999999
This is my code to read the file :
table=app.UItable;
C=readtable(fullpath,’VariableNamingRule’,’preserve’,’FileType’,’text’);
C=table2array(C); % Wasn’t sure if I needed this
opts = detectImportOptions(fullpath)
opts.VariableNames
ReportMessage(app,’Opened Successfully’)
table.Data=C;
Its not reading in the variable name
The opts.variablenames is showing the variable names are present
ans =
1×6 cell array
{‘Idx’} {‘pos’} {‘sep1’} {‘sep2’} {‘avgsep’} {‘deltaPix’}
and opts is:
opts =
DelimitedTextImportOptions with properties:
Format Properties:
Delimiter: {‘,’}
Whitespace: ‘bt ‘
LineEnding: {‘n’ ‘r’ ‘rn’}
CommentStyle: {}
ConsecutiveDelimitersRule: ‘split’
LeadingDelimitersRule: ‘keep’
TrailingDelimitersRule: ‘ignore’
EmptyLineRule: ‘skip’
Encoding: ‘UTF-8’
Replacement Properties:
MissingRule: ‘fill’
ImportErrorRule: ‘fill’
ExtraColumnsRule: ‘addvars’
Variable Import Properties: Set types by name using setvartype
VariableNames: {‘Idx’, ‘pos’, ‘sep1’ … and 3 more}
VariableTypes: {‘double’, ‘double’, ‘double’ … and 3 more}
SelectedVariableNames: {‘Idx’, ‘pos’, ‘sep1’ … and 3 more}
VariableOptions: Show all 6 VariableOptions
Access VariableOptions sub-properties using setvaropts/getvaropts
VariableNamingRule: ‘modify’
Any reason why the variable names aren’t being populated into the uitable?
Thanks Hi, I am trying to read a csv files into a uitable and am having problems reading the variable names in. The csv was saved using writetable and the first few lines are here:
Idx,pos,sep1,sep2,avgsep,deltaPix
1,101.1,1799.918,1868.078,1833.998,0.769999999999
2,101.2,1801.527,1868.695,1835.111,1.88299999999
3,101.3,1802.028,1869.09,1835.559,2.3309999999
4,101.4,1801.645,1869.739,1835.692,2.46399999999
5,101.5,1802.023,1869.453,1835.738,2.50999999999
This is my code to read the file :
table=app.UItable;
C=readtable(fullpath,’VariableNamingRule’,’preserve’,’FileType’,’text’);
C=table2array(C); % Wasn’t sure if I needed this
opts = detectImportOptions(fullpath)
opts.VariableNames
ReportMessage(app,’Opened Successfully’)
table.Data=C;
Its not reading in the variable name
The opts.variablenames is showing the variable names are present
ans =
1×6 cell array
{‘Idx’} {‘pos’} {‘sep1’} {‘sep2’} {‘avgsep’} {‘deltaPix’}
and opts is:
opts =
DelimitedTextImportOptions with properties:
Format Properties:
Delimiter: {‘,’}
Whitespace: ‘bt ‘
LineEnding: {‘n’ ‘r’ ‘rn’}
CommentStyle: {}
ConsecutiveDelimitersRule: ‘split’
LeadingDelimitersRule: ‘keep’
TrailingDelimitersRule: ‘ignore’
EmptyLineRule: ‘skip’
Encoding: ‘UTF-8’
Replacement Properties:
MissingRule: ‘fill’
ImportErrorRule: ‘fill’
ExtraColumnsRule: ‘addvars’
Variable Import Properties: Set types by name using setvartype
VariableNames: {‘Idx’, ‘pos’, ‘sep1’ … and 3 more}
VariableTypes: {‘double’, ‘double’, ‘double’ … and 3 more}
SelectedVariableNames: {‘Idx’, ‘pos’, ‘sep1’ … and 3 more}
VariableOptions: Show all 6 VariableOptions
Access VariableOptions sub-properties using setvaropts/getvaropts
VariableNamingRule: ‘modify’
Any reason why the variable names aren’t being populated into the uitable?
Thanks readmatrix, uitable, variablenames MATLAB Answers — New Questions
how to optimize block toeplitz matrix ?
how to optimize block toeplitz matrix in matlab
I want to create a block lower triangular with block teoplitz matrice starting from second column
in code
block_size1= nts * npt;
% Construct Block Matrices
[tp] = cell(nts, nts);
tp{1} = zeros(npt); tp{2} = zeros(npt);for n=3:nts, tp{n}=rand(npt);end
A_T = sparse(block_size1, block_size1);
for col = 2:nts
for row = col:nts
rowStart = (row – 1) * npt + 1;
rowEnd = rowStart + npt – 1;
colStart = (col – 1) * npt + 1;
colEnd = colStart + npt – 1;
A_T(rowStart:rowEnd, colStart:colEnd) = tp{row – col + 2};
end
end
we know that MATLAB does have a built-in function like toeplitz for cell arrays of matrices, but I want to optimize this code to:
Minimize computation time.
Reduce memory usage (if possible).how to optimize block toeplitz matrix in matlab
I want to create a block lower triangular with block teoplitz matrice starting from second column
in code
block_size1= nts * npt;
% Construct Block Matrices
[tp] = cell(nts, nts);
tp{1} = zeros(npt); tp{2} = zeros(npt);for n=3:nts, tp{n}=rand(npt);end
A_T = sparse(block_size1, block_size1);
for col = 2:nts
for row = col:nts
rowStart = (row – 1) * npt + 1;
rowEnd = rowStart + npt – 1;
colStart = (col – 1) * npt + 1;
colEnd = colStart + npt – 1;
A_T(rowStart:rowEnd, colStart:colEnd) = tp{row – col + 2};
end
end
we know that MATLAB does have a built-in function like toeplitz for cell arrays of matrices, but I want to optimize this code to:
Minimize computation time.
Reduce memory usage (if possible). how to optimize block toeplitz matrix in matlab
I want to create a block lower triangular with block teoplitz matrice starting from second column
in code
block_size1= nts * npt;
% Construct Block Matrices
[tp] = cell(nts, nts);
tp{1} = zeros(npt); tp{2} = zeros(npt);for n=3:nts, tp{n}=rand(npt);end
A_T = sparse(block_size1, block_size1);
for col = 2:nts
for row = col:nts
rowStart = (row – 1) * npt + 1;
rowEnd = rowStart + npt – 1;
colStart = (col – 1) * npt + 1;
colEnd = colStart + npt – 1;
A_T(rowStart:rowEnd, colStart:colEnd) = tp{row – col + 2};
end
end
we know that MATLAB does have a built-in function like toeplitz for cell arrays of matrices, but I want to optimize this code to:
Minimize computation time.
Reduce memory usage (if possible). toeplitz, optimization, code generation MATLAB Answers — New Questions
MATLAB crashes when run on a virtual machine
I am attempting to run MATLAB on my virtual machine. When I do so, however, MATLAB crashes with references to "vm3dgl64.dll" in the stack trace, such as the snippets below:
[ 2] 0x00007ffd5899e3fe C:Program FilesMATLABR2024abinwin64libmwfl.dll+00058366
[ 5] 0x00007ffd3fd2c5bf C:Program FilesMATLABR2024abinwin64jmi.dll+00705983
[ 6] 0x00000000583a9ead C:Program FilesMATLABR2024asysjavajrewin64jrebinserverjvm.dll+02727597
[ 11] 0x00007ffe1da848ff C:windowsSYSTEM32ntdll.dll+00674047
[ 14] 0x00007ffdca59696d C:windowsSYSTEM32vm3dgl64.dll+14903661
[ 39] 0x00007ffdea4411f0 C:windowssystem32opengl32.dll+00135664
I am using Windows Server on my VMWare virtual machine, and am attempting to run MATLAB R2022b. What can I do to resolve this issue?I am attempting to run MATLAB on my virtual machine. When I do so, however, MATLAB crashes with references to "vm3dgl64.dll" in the stack trace, such as the snippets below:
[ 2] 0x00007ffd5899e3fe C:Program FilesMATLABR2024abinwin64libmwfl.dll+00058366
[ 5] 0x00007ffd3fd2c5bf C:Program FilesMATLABR2024abinwin64jmi.dll+00705983
[ 6] 0x00000000583a9ead C:Program FilesMATLABR2024asysjavajrewin64jrebinserverjvm.dll+02727597
[ 11] 0x00007ffe1da848ff C:windowsSYSTEM32ntdll.dll+00674047
[ 14] 0x00007ffdca59696d C:windowsSYSTEM32vm3dgl64.dll+14903661
[ 39] 0x00007ffdea4411f0 C:windowssystem32opengl32.dll+00135664
I am using Windows Server on my VMWare virtual machine, and am attempting to run MATLAB R2022b. What can I do to resolve this issue? I am attempting to run MATLAB on my virtual machine. When I do so, however, MATLAB crashes with references to "vm3dgl64.dll" in the stack trace, such as the snippets below:
[ 2] 0x00007ffd5899e3fe C:Program FilesMATLABR2024abinwin64libmwfl.dll+00058366
[ 5] 0x00007ffd3fd2c5bf C:Program FilesMATLABR2024abinwin64jmi.dll+00705983
[ 6] 0x00000000583a9ead C:Program FilesMATLABR2024asysjavajrewin64jrebinserverjvm.dll+02727597
[ 11] 0x00007ffe1da848ff C:windowsSYSTEM32ntdll.dll+00674047
[ 14] 0x00007ffdca59696d C:windowsSYSTEM32vm3dgl64.dll+14903661
[ 39] 0x00007ffdea4411f0 C:windowssystem32opengl32.dll+00135664
I am using Windows Server on my VMWare virtual machine, and am attempting to run MATLAB R2022b. What can I do to resolve this issue? vm, vm3dgl64.dll, graphics, driver MATLAB Answers — New Questions
Handling Numerical Instability in Estimating Angle Between 2D Points
Hi! I would like to estimate the angle between points using the following code.
x = randn(10000, 1); y = randn(10000, 1);
angle_mat = zeros(length(x));
for i = 1:length(x)
for j = 1:length(x)
if i ~= j
angle_mat(i,j) = atan2(y(j)-y(i), x(j)-x(i));
else
angle_mat(i,j) = NaN;
end
end
end
I realized, however, that, due to numerical instability near horizontal/vertical slopes, the angle estimate near 0/+-pi became weird. Does anyone know how to acount for this numerical instability?Hi! I would like to estimate the angle between points using the following code.
x = randn(10000, 1); y = randn(10000, 1);
angle_mat = zeros(length(x));
for i = 1:length(x)
for j = 1:length(x)
if i ~= j
angle_mat(i,j) = atan2(y(j)-y(i), x(j)-x(i));
else
angle_mat(i,j) = NaN;
end
end
end
I realized, however, that, due to numerical instability near horizontal/vertical slopes, the angle estimate near 0/+-pi became weird. Does anyone know how to acount for this numerical instability? Hi! I would like to estimate the angle between points using the following code.
x = randn(10000, 1); y = randn(10000, 1);
angle_mat = zeros(length(x));
for i = 1:length(x)
for j = 1:length(x)
if i ~= j
angle_mat(i,j) = atan2(y(j)-y(i), x(j)-x(i));
else
angle_mat(i,j) = NaN;
end
end
end
I realized, however, that, due to numerical instability near horizontal/vertical slopes, the angle estimate near 0/+-pi became weird. Does anyone know how to acount for this numerical instability? matlab, numerical instability MATLAB Answers — New Questions
Error in the diagonalization of the Hamiltonian of the Zeeman effect
Hi. I am calculating the energy shifts in the Cs-133 atom due to external magnetic fields by the Zeeman effect (my code is attached). For the ground state and the D1 line I have no problem, the code works fine, the plots give as the D. Steck paper. However, when I try to do it for the D2 line, it seems that the lines of different colors are mixed, which gives incorrect results, as seen in the attached image.
In the code, I construct the Hamiltonian for each magnetic field value and diagonalize the Hamiltonian. One way I got it to work is to diagonalize the Hamiltonian symbolically and then substitute the magnetic field values. However, this method takes too long, and when I tried to add the octupolar term, it does not work. I think it is a problem in the order of the eigenvalues, but I have not been able to solve it. If someone could help me, I would be eternally grateful.
This is the result I obtain.
This is the result of the reference document. In this case, the lines of different colors are not mixed.
The reference document is attached below.
Cesium D Line Data
clc
clear variables
close all
tic
%% Constants definition
line = ‘D2’; % [Ground D1 D2]
I = 7/2; % Nuclear spin
g_I = -0.00039885395; % Nuclear g-factor
J = [1/2 3/2]; % Total angular momentum
g_J = [2.002540261 0.665900 1.33408749]; % Fine structure g-factor
mu_B = (9.27400899E-24)*1E-4; % Bohr Magneton (J/G)
hbar = 1.054E-34; % Reduced Planck’s constant (Js)
Ahfs = 2*pi*hbar*[2.2981579425E9 291.9201E6 50.28827E6]; % Magnetic Dipole Constant
Bhfs = -2*pi*hbar*0.4934E6; % Electric Quadrupole Constant 5^2 P_3/2
Chfs = 2*pi*hbar*0.560E3; % Magnetic Octupole Constant 6^2 P_3/D2
Folder = pwd;
switch line
case ‘Ground’
A = Ahfs(1);
J = J(1); % Total angular momentum
g_J = g_J(1);
BF = linspace(0,15000,1000); % Magnetic field vector (G)
titleg = ‘$ ^{133}mathrm{Cs} , , , 6^2 mathrm{S}_{1/2}$’;
yl = ‘$E/h$ (GHz)’;
Amp = 1E-9;
yy = [-26 26];
str = ‘Ground state’;
case ‘D1’
A = Ahfs(2);
J = J(1); % Total angular momentum
g_J = g_J(2);
BF = linspace(0,5000,1000); % Magnetic field vector (G)
titleg = ‘$ ^{133}mathrm{Cs} , , , 6^2 mathrm{P}_{1/2}$’;
yl = ‘$E/h$ (GHz)’;
Amp = 1E-9;
yy = [-2.5 2.5];
str = ‘D1 line’;
case ‘D2’
A = Ahfs(3);
J = J(2); % Total angular momentum
g_J = g_J(3);
BF = linspace(0,500,1000); % Magnetic field vector (G)
titleg = ‘$ ^{133}mathrm{Cs} , , , 6^2 mathrm{P}_{3/2}$’;
yl = ‘$E/h$ (MHz)’;
Amp = 1E-6;
yy = [-1500 1500];
str = ‘D2 line’;
otherwise
error(‘Unexpected value of state.’);
end
%%
% Get the spin operator matrices for I and J
[SxI, SyI, SzI] = espin(I);
[SxJ, SyJ, SzJ] = espin(J);
% Construct the spin operators, defined as the tensor product of the spin matrices S(I) and S(J) with
% indetity matrices 1(I) and 1(J)
Ix = kron(SxI, id(J));
Iy = kron(SyI, id(J));
Iz = kron(SzI, id(J));
Jx = kron(id(I), SxJ);
Jy = kron(id(I), SyJ);
Jz = kron(id(I), SzJ);
F_values = abs(I-J):(I+J);
degeneracies = 2*F_values + 1; % Degeneracies for each F value
%% We diagonalize the Hamiltonian symbolically and then evaluate the eigenvalues in terms of the external magnetic field
energies = zeros(length(BF), (2*I+1)*(2*J+1)); % Preallocate energy array
% Check the value of J before entering the loop
if J == 1/2
% Construct Hamiltonian for J = 1/2
HZeemanBase = A*(Ix*Jx + Iy*Jy + Iz*Jz) + …
mu_B*BF(1)*(g_I*Iz + g_J*Jz); % Use BF(1) just as a placeholder for the structure
elseif J == 3/2
% Construct Hamiltonian for J = 3/2
HZeemanBase = A*(Ix*Jx + Iy*Jy + Iz*Jz) + …
mu_B*BF(1)*(g_I*Iz + g_J*Jz) + …
(Bhfs/(2*I*(2*I-1)*J*(2*J-1)))*( 3*(Ix*Jx + Iy*Jy + Iz*Jz).^2 + (3/2)*(Ix*Jx + Iy*Jy + Iz*Jz) – (Ix.^2 + Iy.^2 + Iz.^2)*(Jx.^2 + Jy.^2 + Jz.^2) );
end
for j = 1:length(BF)
% Modify the Hamiltonian for each BF(j)
HZeeman = HZeemanBase;
% Update the Zeeman term for the current magnetic field strength
HZeeman = (Amp/(2*pi*hbar))*(HZeeman + mu_B*BF(j)*(g_I*Iz + g_J*Jz));
% Diagonalize the Hamiltonian
[eigenvectors, eigenvalues] = eig(HZeeman);
% Store the eigenvalues (energies)
energies(j, 🙂 = sort(diag(real(eigenvalues))); % Sort energies for clarity
end
% Plot levels for each F group with different colors
colors = {‘r’, ‘b’, ‘g’, ‘m’, ‘k’}; % Colors for each F group
level_start = 1; % Start index for each F group
legend_handles = []; % Store plot handles for the legend
Fig = figure;
hold on;
for f_idx = 1:length(F_values)
num_levels_in_group = degeneracies(f_idx); % Number of levels for this F
level_end = level_start + num_levels_in_group – 1; % End index for this F
h = plot(BF, energies(:, level_start:level_end), ‘LineWidth’,2, ‘Color’, colors{f_idx});
legend_handles = [legend_handles, h(1)]; % Store one handle per group
level_start = level_end + 1; % Update start index for the next F group
end
set(gca, ‘xminortick’, ‘on’, ‘TickLabelInterpreter’,’latex’,’fontsize’,18);
set(gca, ‘yminortick’, ‘on’, ‘TickLabelInterpreter’,’latex’,’fontsize’,18);
xlabel(‘$|B|$ (G)’, ‘Interpreter’, ‘latex’, ‘Fontsize’, 20);
ylabel(yl, ‘Interpreter’, ‘latex’,’Fontsize’, 20);
ylim(yy);
title(titleg,’Interpreter’, ‘latex’, ‘Fontsize’, 22);
legend_labels = arrayfun(@(f) sprintf(‘$F = %.0f$’, f), F_values, ‘UniformOutput’, false);
legend(legend_handles, legend_labels, ‘Interpreter’, ‘latex’, ‘Location’, ‘northwest’);
box on;
hold off;
Filename = sprintf(‘%s/Zeeman splitting %s.png’, Folder, str);
print(Fig, Filename, ‘-dpng’, ‘-r300’);
tocHi. I am calculating the energy shifts in the Cs-133 atom due to external magnetic fields by the Zeeman effect (my code is attached). For the ground state and the D1 line I have no problem, the code works fine, the plots give as the D. Steck paper. However, when I try to do it for the D2 line, it seems that the lines of different colors are mixed, which gives incorrect results, as seen in the attached image.
In the code, I construct the Hamiltonian for each magnetic field value and diagonalize the Hamiltonian. One way I got it to work is to diagonalize the Hamiltonian symbolically and then substitute the magnetic field values. However, this method takes too long, and when I tried to add the octupolar term, it does not work. I think it is a problem in the order of the eigenvalues, but I have not been able to solve it. If someone could help me, I would be eternally grateful.
This is the result I obtain.
This is the result of the reference document. In this case, the lines of different colors are not mixed.
The reference document is attached below.
Cesium D Line Data
clc
clear variables
close all
tic
%% Constants definition
line = ‘D2’; % [Ground D1 D2]
I = 7/2; % Nuclear spin
g_I = -0.00039885395; % Nuclear g-factor
J = [1/2 3/2]; % Total angular momentum
g_J = [2.002540261 0.665900 1.33408749]; % Fine structure g-factor
mu_B = (9.27400899E-24)*1E-4; % Bohr Magneton (J/G)
hbar = 1.054E-34; % Reduced Planck’s constant (Js)
Ahfs = 2*pi*hbar*[2.2981579425E9 291.9201E6 50.28827E6]; % Magnetic Dipole Constant
Bhfs = -2*pi*hbar*0.4934E6; % Electric Quadrupole Constant 5^2 P_3/2
Chfs = 2*pi*hbar*0.560E3; % Magnetic Octupole Constant 6^2 P_3/D2
Folder = pwd;
switch line
case ‘Ground’
A = Ahfs(1);
J = J(1); % Total angular momentum
g_J = g_J(1);
BF = linspace(0,15000,1000); % Magnetic field vector (G)
titleg = ‘$ ^{133}mathrm{Cs} , , , 6^2 mathrm{S}_{1/2}$’;
yl = ‘$E/h$ (GHz)’;
Amp = 1E-9;
yy = [-26 26];
str = ‘Ground state’;
case ‘D1’
A = Ahfs(2);
J = J(1); % Total angular momentum
g_J = g_J(2);
BF = linspace(0,5000,1000); % Magnetic field vector (G)
titleg = ‘$ ^{133}mathrm{Cs} , , , 6^2 mathrm{P}_{1/2}$’;
yl = ‘$E/h$ (GHz)’;
Amp = 1E-9;
yy = [-2.5 2.5];
str = ‘D1 line’;
case ‘D2’
A = Ahfs(3);
J = J(2); % Total angular momentum
g_J = g_J(3);
BF = linspace(0,500,1000); % Magnetic field vector (G)
titleg = ‘$ ^{133}mathrm{Cs} , , , 6^2 mathrm{P}_{3/2}$’;
yl = ‘$E/h$ (MHz)’;
Amp = 1E-6;
yy = [-1500 1500];
str = ‘D2 line’;
otherwise
error(‘Unexpected value of state.’);
end
%%
% Get the spin operator matrices for I and J
[SxI, SyI, SzI] = espin(I);
[SxJ, SyJ, SzJ] = espin(J);
% Construct the spin operators, defined as the tensor product of the spin matrices S(I) and S(J) with
% indetity matrices 1(I) and 1(J)
Ix = kron(SxI, id(J));
Iy = kron(SyI, id(J));
Iz = kron(SzI, id(J));
Jx = kron(id(I), SxJ);
Jy = kron(id(I), SyJ);
Jz = kron(id(I), SzJ);
F_values = abs(I-J):(I+J);
degeneracies = 2*F_values + 1; % Degeneracies for each F value
%% We diagonalize the Hamiltonian symbolically and then evaluate the eigenvalues in terms of the external magnetic field
energies = zeros(length(BF), (2*I+1)*(2*J+1)); % Preallocate energy array
% Check the value of J before entering the loop
if J == 1/2
% Construct Hamiltonian for J = 1/2
HZeemanBase = A*(Ix*Jx + Iy*Jy + Iz*Jz) + …
mu_B*BF(1)*(g_I*Iz + g_J*Jz); % Use BF(1) just as a placeholder for the structure
elseif J == 3/2
% Construct Hamiltonian for J = 3/2
HZeemanBase = A*(Ix*Jx + Iy*Jy + Iz*Jz) + …
mu_B*BF(1)*(g_I*Iz + g_J*Jz) + …
(Bhfs/(2*I*(2*I-1)*J*(2*J-1)))*( 3*(Ix*Jx + Iy*Jy + Iz*Jz).^2 + (3/2)*(Ix*Jx + Iy*Jy + Iz*Jz) – (Ix.^2 + Iy.^2 + Iz.^2)*(Jx.^2 + Jy.^2 + Jz.^2) );
end
for j = 1:length(BF)
% Modify the Hamiltonian for each BF(j)
HZeeman = HZeemanBase;
% Update the Zeeman term for the current magnetic field strength
HZeeman = (Amp/(2*pi*hbar))*(HZeeman + mu_B*BF(j)*(g_I*Iz + g_J*Jz));
% Diagonalize the Hamiltonian
[eigenvectors, eigenvalues] = eig(HZeeman);
% Store the eigenvalues (energies)
energies(j, 🙂 = sort(diag(real(eigenvalues))); % Sort energies for clarity
end
% Plot levels for each F group with different colors
colors = {‘r’, ‘b’, ‘g’, ‘m’, ‘k’}; % Colors for each F group
level_start = 1; % Start index for each F group
legend_handles = []; % Store plot handles for the legend
Fig = figure;
hold on;
for f_idx = 1:length(F_values)
num_levels_in_group = degeneracies(f_idx); % Number of levels for this F
level_end = level_start + num_levels_in_group – 1; % End index for this F
h = plot(BF, energies(:, level_start:level_end), ‘LineWidth’,2, ‘Color’, colors{f_idx});
legend_handles = [legend_handles, h(1)]; % Store one handle per group
level_start = level_end + 1; % Update start index for the next F group
end
set(gca, ‘xminortick’, ‘on’, ‘TickLabelInterpreter’,’latex’,’fontsize’,18);
set(gca, ‘yminortick’, ‘on’, ‘TickLabelInterpreter’,’latex’,’fontsize’,18);
xlabel(‘$|B|$ (G)’, ‘Interpreter’, ‘latex’, ‘Fontsize’, 20);
ylabel(yl, ‘Interpreter’, ‘latex’,’Fontsize’, 20);
ylim(yy);
title(titleg,’Interpreter’, ‘latex’, ‘Fontsize’, 22);
legend_labels = arrayfun(@(f) sprintf(‘$F = %.0f$’, f), F_values, ‘UniformOutput’, false);
legend(legend_handles, legend_labels, ‘Interpreter’, ‘latex’, ‘Location’, ‘northwest’);
box on;
hold off;
Filename = sprintf(‘%s/Zeeman splitting %s.png’, Folder, str);
print(Fig, Filename, ‘-dpng’, ‘-r300’);
toc Hi. I am calculating the energy shifts in the Cs-133 atom due to external magnetic fields by the Zeeman effect (my code is attached). For the ground state and the D1 line I have no problem, the code works fine, the plots give as the D. Steck paper. However, when I try to do it for the D2 line, it seems that the lines of different colors are mixed, which gives incorrect results, as seen in the attached image.
In the code, I construct the Hamiltonian for each magnetic field value and diagonalize the Hamiltonian. One way I got it to work is to diagonalize the Hamiltonian symbolically and then substitute the magnetic field values. However, this method takes too long, and when I tried to add the octupolar term, it does not work. I think it is a problem in the order of the eigenvalues, but I have not been able to solve it. If someone could help me, I would be eternally grateful.
This is the result I obtain.
This is the result of the reference document. In this case, the lines of different colors are not mixed.
The reference document is attached below.
Cesium D Line Data
clc
clear variables
close all
tic
%% Constants definition
line = ‘D2’; % [Ground D1 D2]
I = 7/2; % Nuclear spin
g_I = -0.00039885395; % Nuclear g-factor
J = [1/2 3/2]; % Total angular momentum
g_J = [2.002540261 0.665900 1.33408749]; % Fine structure g-factor
mu_B = (9.27400899E-24)*1E-4; % Bohr Magneton (J/G)
hbar = 1.054E-34; % Reduced Planck’s constant (Js)
Ahfs = 2*pi*hbar*[2.2981579425E9 291.9201E6 50.28827E6]; % Magnetic Dipole Constant
Bhfs = -2*pi*hbar*0.4934E6; % Electric Quadrupole Constant 5^2 P_3/2
Chfs = 2*pi*hbar*0.560E3; % Magnetic Octupole Constant 6^2 P_3/D2
Folder = pwd;
switch line
case ‘Ground’
A = Ahfs(1);
J = J(1); % Total angular momentum
g_J = g_J(1);
BF = linspace(0,15000,1000); % Magnetic field vector (G)
titleg = ‘$ ^{133}mathrm{Cs} , , , 6^2 mathrm{S}_{1/2}$’;
yl = ‘$E/h$ (GHz)’;
Amp = 1E-9;
yy = [-26 26];
str = ‘Ground state’;
case ‘D1’
A = Ahfs(2);
J = J(1); % Total angular momentum
g_J = g_J(2);
BF = linspace(0,5000,1000); % Magnetic field vector (G)
titleg = ‘$ ^{133}mathrm{Cs} , , , 6^2 mathrm{P}_{1/2}$’;
yl = ‘$E/h$ (GHz)’;
Amp = 1E-9;
yy = [-2.5 2.5];
str = ‘D1 line’;
case ‘D2’
A = Ahfs(3);
J = J(2); % Total angular momentum
g_J = g_J(3);
BF = linspace(0,500,1000); % Magnetic field vector (G)
titleg = ‘$ ^{133}mathrm{Cs} , , , 6^2 mathrm{P}_{3/2}$’;
yl = ‘$E/h$ (MHz)’;
Amp = 1E-6;
yy = [-1500 1500];
str = ‘D2 line’;
otherwise
error(‘Unexpected value of state.’);
end
%%
% Get the spin operator matrices for I and J
[SxI, SyI, SzI] = espin(I);
[SxJ, SyJ, SzJ] = espin(J);
% Construct the spin operators, defined as the tensor product of the spin matrices S(I) and S(J) with
% indetity matrices 1(I) and 1(J)
Ix = kron(SxI, id(J));
Iy = kron(SyI, id(J));
Iz = kron(SzI, id(J));
Jx = kron(id(I), SxJ);
Jy = kron(id(I), SyJ);
Jz = kron(id(I), SzJ);
F_values = abs(I-J):(I+J);
degeneracies = 2*F_values + 1; % Degeneracies for each F value
%% We diagonalize the Hamiltonian symbolically and then evaluate the eigenvalues in terms of the external magnetic field
energies = zeros(length(BF), (2*I+1)*(2*J+1)); % Preallocate energy array
% Check the value of J before entering the loop
if J == 1/2
% Construct Hamiltonian for J = 1/2
HZeemanBase = A*(Ix*Jx + Iy*Jy + Iz*Jz) + …
mu_B*BF(1)*(g_I*Iz + g_J*Jz); % Use BF(1) just as a placeholder for the structure
elseif J == 3/2
% Construct Hamiltonian for J = 3/2
HZeemanBase = A*(Ix*Jx + Iy*Jy + Iz*Jz) + …
mu_B*BF(1)*(g_I*Iz + g_J*Jz) + …
(Bhfs/(2*I*(2*I-1)*J*(2*J-1)))*( 3*(Ix*Jx + Iy*Jy + Iz*Jz).^2 + (3/2)*(Ix*Jx + Iy*Jy + Iz*Jz) – (Ix.^2 + Iy.^2 + Iz.^2)*(Jx.^2 + Jy.^2 + Jz.^2) );
end
for j = 1:length(BF)
% Modify the Hamiltonian for each BF(j)
HZeeman = HZeemanBase;
% Update the Zeeman term for the current magnetic field strength
HZeeman = (Amp/(2*pi*hbar))*(HZeeman + mu_B*BF(j)*(g_I*Iz + g_J*Jz));
% Diagonalize the Hamiltonian
[eigenvectors, eigenvalues] = eig(HZeeman);
% Store the eigenvalues (energies)
energies(j, 🙂 = sort(diag(real(eigenvalues))); % Sort energies for clarity
end
% Plot levels for each F group with different colors
colors = {‘r’, ‘b’, ‘g’, ‘m’, ‘k’}; % Colors for each F group
level_start = 1; % Start index for each F group
legend_handles = []; % Store plot handles for the legend
Fig = figure;
hold on;
for f_idx = 1:length(F_values)
num_levels_in_group = degeneracies(f_idx); % Number of levels for this F
level_end = level_start + num_levels_in_group – 1; % End index for this F
h = plot(BF, energies(:, level_start:level_end), ‘LineWidth’,2, ‘Color’, colors{f_idx});
legend_handles = [legend_handles, h(1)]; % Store one handle per group
level_start = level_end + 1; % Update start index for the next F group
end
set(gca, ‘xminortick’, ‘on’, ‘TickLabelInterpreter’,’latex’,’fontsize’,18);
set(gca, ‘yminortick’, ‘on’, ‘TickLabelInterpreter’,’latex’,’fontsize’,18);
xlabel(‘$|B|$ (G)’, ‘Interpreter’, ‘latex’, ‘Fontsize’, 20);
ylabel(yl, ‘Interpreter’, ‘latex’,’Fontsize’, 20);
ylim(yy);
title(titleg,’Interpreter’, ‘latex’, ‘Fontsize’, 22);
legend_labels = arrayfun(@(f) sprintf(‘$F = %.0f$’, f), F_values, ‘UniformOutput’, false);
legend(legend_handles, legend_labels, ‘Interpreter’, ‘latex’, ‘Location’, ‘northwest’);
box on;
hold off;
Filename = sprintf(‘%s/Zeeman splitting %s.png’, Folder, str);
print(Fig, Filename, ‘-dpng’, ‘-r300’);
toc matrix, eigenvalues, diagonalization, atomic physics MATLAB Answers — New Questions
Issue with Rapid Accelerator Mode in parsim After Upgrading to R2024b
I am encountering issues with the workers in parsim when using the Rapid Accelerator mode.
After upgrading from R2024a to R2024b one week ago, I noticed that running parsim simulations no longer works as expected. I aim to run 6 simulations on a system with 6 physical (P) cores, allowing Matlab to compute all simulations simultaneously. However, only one worker completes the simulation, while the remaining five remain stuck in the "Running" state.
I tested this behavior with 6 identical models, but the issue persisted. Uninstalling and reinstalling Matlab did not do the trick.
Another observation is related to CPU behavior. When the parsim simulation starts, my laptop’s fan runs intensively, and some CPU cores reach 100% utilization—this is expected and matches the behavior in R2024a. However, as soon as the first worker completes its simulation, the fan slows down, and CPU utilization becomes erratic. The CPU usage fluctuates significantly, jumping between 20% and 90%.
Additionally, if I stop the parsim simulation via the Simulation Manager, Matlab becomes stuck at the "Cleaning up parallel worker" stage for the workers that were stuck during the simulation.
Interestingly, when switching from Rapid Accelerator to Accelerator mode, the parsim simulations work correctly, and some CPU cores consistently run at 100% utilization.
Does anyone have a clue what the cause for this behavior?I am encountering issues with the workers in parsim when using the Rapid Accelerator mode.
After upgrading from R2024a to R2024b one week ago, I noticed that running parsim simulations no longer works as expected. I aim to run 6 simulations on a system with 6 physical (P) cores, allowing Matlab to compute all simulations simultaneously. However, only one worker completes the simulation, while the remaining five remain stuck in the "Running" state.
I tested this behavior with 6 identical models, but the issue persisted. Uninstalling and reinstalling Matlab did not do the trick.
Another observation is related to CPU behavior. When the parsim simulation starts, my laptop’s fan runs intensively, and some CPU cores reach 100% utilization—this is expected and matches the behavior in R2024a. However, as soon as the first worker completes its simulation, the fan slows down, and CPU utilization becomes erratic. The CPU usage fluctuates significantly, jumping between 20% and 90%.
Additionally, if I stop the parsim simulation via the Simulation Manager, Matlab becomes stuck at the "Cleaning up parallel worker" stage for the workers that were stuck during the simulation.
Interestingly, when switching from Rapid Accelerator to Accelerator mode, the parsim simulations work correctly, and some CPU cores consistently run at 100% utilization.
Does anyone have a clue what the cause for this behavior? I am encountering issues with the workers in parsim when using the Rapid Accelerator mode.
After upgrading from R2024a to R2024b one week ago, I noticed that running parsim simulations no longer works as expected. I aim to run 6 simulations on a system with 6 physical (P) cores, allowing Matlab to compute all simulations simultaneously. However, only one worker completes the simulation, while the remaining five remain stuck in the "Running" state.
I tested this behavior with 6 identical models, but the issue persisted. Uninstalling and reinstalling Matlab did not do the trick.
Another observation is related to CPU behavior. When the parsim simulation starts, my laptop’s fan runs intensively, and some CPU cores reach 100% utilization—this is expected and matches the behavior in R2024a. However, as soon as the first worker completes its simulation, the fan slows down, and CPU utilization becomes erratic. The CPU usage fluctuates significantly, jumping between 20% and 90%.
Additionally, if I stop the parsim simulation via the Simulation Manager, Matlab becomes stuck at the "Cleaning up parallel worker" stage for the workers that were stuck during the simulation.
Interestingly, when switching from Rapid Accelerator to Accelerator mode, the parsim simulations work correctly, and some CPU cores consistently run at 100% utilization.
Does anyone have a clue what the cause for this behavior? parsim, rapid accelerator MATLAB Answers — New Questions
How to detect ArUco markers in MATLAB?
I want to read ArUco markers using MATLAB for my workflow.
Does MATLAB support reading ArUco markers?I want to read ArUco markers using MATLAB for my workflow.
Does MATLAB support reading ArUco markers? I want to read ArUco markers using MATLAB for my workflow.
Does MATLAB support reading ArUco markers? opencv, computer, vision, toolbox, aruco, readarucomarker, generatearucomarker MATLAB Answers — New Questions