Author: PuTI
matlab -batch on SLURM prints errors when HOME is shared across many nodes
When launching MATLAB in batch mode on a SLURM cluster, stderr shows:
terminate called after throwing an instance of ‘matlabconnector::installationsregistry::InstallationsRegistryError’
what(): InstallationsRegistry:getMatlabConnectorVersion: More than one MATLAB Connector records were found
This appears during startup (even for a simple command like matlab -batch "disp(version); exit").
sbatch command (PROGLIST=/work/share/…/matlab2024a/bin/matlab):
srun "$PROGLIST" -batch "$CMD"
Find files in ~/.MATLABConnector as below:
~/.MATLABConnector/b01r2n13/LatestInstall.info
~/.MATLABConnector/b01r2n13/UpdatePending.json
~/.MATLABConnector/b01r2n13/locks
~/.MATLABConnector/b02r2n01/LatestInstall.info
~/.MATLABConnector/b02r2n01/UpdatePending.json
~/.MATLABConnector/b02r2n01/locks
…
Questions
Is this a known issue with MATLAB Connector on HPC systems where $HOME is shared across many nodes?
How to prevent MATLAB from throwing this error at startup?When launching MATLAB in batch mode on a SLURM cluster, stderr shows:
terminate called after throwing an instance of ‘matlabconnector::installationsregistry::InstallationsRegistryError’
what(): InstallationsRegistry:getMatlabConnectorVersion: More than one MATLAB Connector records were found
This appears during startup (even for a simple command like matlab -batch "disp(version); exit").
sbatch command (PROGLIST=/work/share/…/matlab2024a/bin/matlab):
srun "$PROGLIST" -batch "$CMD"
Find files in ~/.MATLABConnector as below:
~/.MATLABConnector/b01r2n13/LatestInstall.info
~/.MATLABConnector/b01r2n13/UpdatePending.json
~/.MATLABConnector/b01r2n13/locks
~/.MATLABConnector/b02r2n01/LatestInstall.info
~/.MATLABConnector/b02r2n01/UpdatePending.json
~/.MATLABConnector/b02r2n01/locks
…
Questions
Is this a known issue with MATLAB Connector on HPC systems where $HOME is shared across many nodes?
How to prevent MATLAB from throwing this error at startup? When launching MATLAB in batch mode on a SLURM cluster, stderr shows:
terminate called after throwing an instance of ‘matlabconnector::installationsregistry::InstallationsRegistryError’
what(): InstallationsRegistry:getMatlabConnectorVersion: More than one MATLAB Connector records were found
This appears during startup (even for a simple command like matlab -batch "disp(version); exit").
sbatch command (PROGLIST=/work/share/…/matlab2024a/bin/matlab):
srun "$PROGLIST" -batch "$CMD"
Find files in ~/.MATLABConnector as below:
~/.MATLABConnector/b01r2n13/LatestInstall.info
~/.MATLABConnector/b01r2n13/UpdatePending.json
~/.MATLABConnector/b01r2n13/locks
~/.MATLABConnector/b02r2n01/LatestInstall.info
~/.MATLABConnector/b02r2n01/UpdatePending.json
~/.MATLABConnector/b02r2n01/locks
…
Questions
Is this a known issue with MATLAB Connector on HPC systems where $HOME is shared across many nodes?
How to prevent MATLAB from throwing this error at startup? linux, batch MATLAB Answers — New Questions
Construct voronoi diagram on a point cloud
I have a point cloud file in the .pcd format. I want to calculate a Voronoi diagram for this .pcd file. I also have a set of points with x and y coordinates that were extracted from the .pcd file. I want to calculate the Voronoi diagram based on these x and y coordinates. My objective is to divide the point cloud into zones corresponding to these points (x, y). So far, I have written the following code but it seems like there is no connection between the point cloud and x-y coordinates. How can I relate the point cloud and the co ordinates?
ptCloud = pcread("test_obj6.pcd");
x = [ 7.0267 4.8436 4.8767 2.8000];
y = [ 4.2001 4.5947 2.1412 3.2000];
voronoi(x,y)I have a point cloud file in the .pcd format. I want to calculate a Voronoi diagram for this .pcd file. I also have a set of points with x and y coordinates that were extracted from the .pcd file. I want to calculate the Voronoi diagram based on these x and y coordinates. My objective is to divide the point cloud into zones corresponding to these points (x, y). So far, I have written the following code but it seems like there is no connection between the point cloud and x-y coordinates. How can I relate the point cloud and the co ordinates?
ptCloud = pcread("test_obj6.pcd");
x = [ 7.0267 4.8436 4.8767 2.8000];
y = [ 4.2001 4.5947 2.1412 3.2000];
voronoi(x,y) I have a point cloud file in the .pcd format. I want to calculate a Voronoi diagram for this .pcd file. I also have a set of points with x and y coordinates that were extracted from the .pcd file. I want to calculate the Voronoi diagram based on these x and y coordinates. My objective is to divide the point cloud into zones corresponding to these points (x, y). So far, I have written the following code but it seems like there is no connection between the point cloud and x-y coordinates. How can I relate the point cloud and the co ordinates?
ptCloud = pcread("test_obj6.pcd");
x = [ 7.0267 4.8436 4.8767 2.8000];
y = [ 4.2001 4.5947 2.1412 3.2000];
voronoi(x,y) matlab MATLAB Answers — New Questions
Linear interpolation with interp1 is slow: How to improve run times?
I wrote a MWE to compare the perforance of interp1 (MATLAB built-in) with my custom interp1_scal (for linear interpolation), using a simple dynamic programming problem solved with value function iteration
$$ V(k) = max_{k’} log(k^alpha-k’)+beta*V(k’) $$
Question 1: I am a bit surprised that the custom interpolation routine I wrote is much faster than the built-in interp1 for linear interpolation (on my laptop with R2024b, it is 4 times faster, here (RUN button) the speed advantage is smaller but still significant). To find the location of the query point xi on the x grid, I am using binary search (see function locate), directly translated from an older Fortran/C routine.
Question 2: Am I using interp1 in the wrong way? would using griddedInterp or other Matlab routines significantly improve run times of this MWE?
Any help, suggestions or comments is greatly appreciated!
P.S. I am glad to provide additional info on the dynamic programming problem that this simple MWE is meant to caputure in few lines of code, if someone asks for.
Minimum Working Example here:
clear,clc,close all
%% Parameters
maxit = 50;
tol = 1e-5;
alpha = 0.33;
beta = 0.96;
k_ss = (alpha * beta)^(1 / (1 – alpha));
n_k = 300;
k_min = 0.5 * k_ss;
k_max = 1.5 * k_ss;
k_grid = linspace(k_min, k_max, n_k)’;
% Precompute output y = k^alpha
y_grid = k_grid .^ alpha;
%% Method 1: value function iteration with Matlab built-in interpolation
tic
% Initialization
V0 = zeros(n_k, 1);
V1 = zeros(n_k, 1);
% Value Function Iteration
for iter=1:maxit
for i = 1:n_k
y_val = y_grid(i);
k_max_now = min(y_val, k_max); % upper bound for Brent minimization
% Objective function (negative value for minimization)
obj = @(kp) -(log(y_val-kp) + beta*interp1(k_grid,V0,kp,’linear’));
% Optimal policy
kp_opt = fminbnd(obj, k_min, k_max_now);
% Updated value function
V1(i) = -obj(kp_opt);
end
% Convergence check
err = max(abs(V1 – V0));
V0 = V1;
end %end iter
time_vfi1=toc;
%% Method 2: value function iteration with *custom* interpolation
tic
% Initialization
V0 = zeros(n_k, 1);
V2 = zeros(n_k, 1);
% Value Function Iteration
for iter=1:maxit
for i_k = 1:n_k
y_val = y_grid(i_k);
k_max_now = min(y_val, k_max);
% Objective function (negative value for minimization)
obj = @(kp) -( log(y_val-kp) + beta*interp1_scal(k_grid,V0,kp) );
% Optimal policy
kp_opt = fminbnd(obj, k_min, k_max_now);
% Updated value function
V2(i_k) = -obj(kp_opt);
end
% Convergence check
err = max(abs(V2 – V0));
V0 = V2;
end %end iter
time_vfi2=toc;
%% Compare vfi1 and vfi2
err_V = max(abs(V1-V2));
disp(‘RESULTS OF COMPARISON’)
fprintf(‘||V1-V2|| = %f n’,err_V)
fprintf(‘Run time of vfi1 with Matlab interp = %f n’,time_vfi1)
fprintf(‘Run time of vfi2 with custom interp = %f n’,time_vfi2)
fprintf(‘time vfi1 / time_vfi2 = %f n’,time_vfi1/time_vfi2)
%% Plot value function
figure;
plot(k_grid, V1, ‘LineWidth’, 1.5);
hold on
plot(k_grid, V2, ‘LineWidth’, 1.5);
legend(‘V1′,’V2’)
xlabel(‘Current capital’);
grid on;
% Fast linear interpolation routine
% Usage:
% yi = interp1_scal(x,y,xi)
% where x and y are column vectors with n elements, xi is a scalar
% and yi is a scalar
% Input Arguments
% x – Sample points
% column vector
% Y – Sample data
% column vector
% xi – Query point
% scalar
function yi = interp1_scal(x,y,xi)
n = size(x,1);
j = locate(x,xi);
j = max(min(j,n-1),1);
slope = (y(j+1)-y(j))/(x(j+1)-x(j));
yi = y(j)+(xi-x(j))*slope;
end %end function interp1_scal
function jl = locate(xx,x)
%function jl = locate(xx,x)
%
% x is between xx(jl) and xx(jl+1)
%
% jl = 0 and jl = n means x is out of range
%
% xx is assumed to be monotone increasing
n = length(xx);
if x<xx(1)
jl = 0;
elseif x>xx(n)
jl = n;
else
jl = 1;
ju = n;
while (ju-jl>1)
jm = floor((ju+jl)/2);
if x>=xx(jm)
jl = jm;
else
ju=jm;
end
end
end
end %end function locateI wrote a MWE to compare the perforance of interp1 (MATLAB built-in) with my custom interp1_scal (for linear interpolation), using a simple dynamic programming problem solved with value function iteration
$$ V(k) = max_{k’} log(k^alpha-k’)+beta*V(k’) $$
Question 1: I am a bit surprised that the custom interpolation routine I wrote is much faster than the built-in interp1 for linear interpolation (on my laptop with R2024b, it is 4 times faster, here (RUN button) the speed advantage is smaller but still significant). To find the location of the query point xi on the x grid, I am using binary search (see function locate), directly translated from an older Fortran/C routine.
Question 2: Am I using interp1 in the wrong way? would using griddedInterp or other Matlab routines significantly improve run times of this MWE?
Any help, suggestions or comments is greatly appreciated!
P.S. I am glad to provide additional info on the dynamic programming problem that this simple MWE is meant to caputure in few lines of code, if someone asks for.
Minimum Working Example here:
clear,clc,close all
%% Parameters
maxit = 50;
tol = 1e-5;
alpha = 0.33;
beta = 0.96;
k_ss = (alpha * beta)^(1 / (1 – alpha));
n_k = 300;
k_min = 0.5 * k_ss;
k_max = 1.5 * k_ss;
k_grid = linspace(k_min, k_max, n_k)’;
% Precompute output y = k^alpha
y_grid = k_grid .^ alpha;
%% Method 1: value function iteration with Matlab built-in interpolation
tic
% Initialization
V0 = zeros(n_k, 1);
V1 = zeros(n_k, 1);
% Value Function Iteration
for iter=1:maxit
for i = 1:n_k
y_val = y_grid(i);
k_max_now = min(y_val, k_max); % upper bound for Brent minimization
% Objective function (negative value for minimization)
obj = @(kp) -(log(y_val-kp) + beta*interp1(k_grid,V0,kp,’linear’));
% Optimal policy
kp_opt = fminbnd(obj, k_min, k_max_now);
% Updated value function
V1(i) = -obj(kp_opt);
end
% Convergence check
err = max(abs(V1 – V0));
V0 = V1;
end %end iter
time_vfi1=toc;
%% Method 2: value function iteration with *custom* interpolation
tic
% Initialization
V0 = zeros(n_k, 1);
V2 = zeros(n_k, 1);
% Value Function Iteration
for iter=1:maxit
for i_k = 1:n_k
y_val = y_grid(i_k);
k_max_now = min(y_val, k_max);
% Objective function (negative value for minimization)
obj = @(kp) -( log(y_val-kp) + beta*interp1_scal(k_grid,V0,kp) );
% Optimal policy
kp_opt = fminbnd(obj, k_min, k_max_now);
% Updated value function
V2(i_k) = -obj(kp_opt);
end
% Convergence check
err = max(abs(V2 – V0));
V0 = V2;
end %end iter
time_vfi2=toc;
%% Compare vfi1 and vfi2
err_V = max(abs(V1-V2));
disp(‘RESULTS OF COMPARISON’)
fprintf(‘||V1-V2|| = %f n’,err_V)
fprintf(‘Run time of vfi1 with Matlab interp = %f n’,time_vfi1)
fprintf(‘Run time of vfi2 with custom interp = %f n’,time_vfi2)
fprintf(‘time vfi1 / time_vfi2 = %f n’,time_vfi1/time_vfi2)
%% Plot value function
figure;
plot(k_grid, V1, ‘LineWidth’, 1.5);
hold on
plot(k_grid, V2, ‘LineWidth’, 1.5);
legend(‘V1′,’V2’)
xlabel(‘Current capital’);
grid on;
% Fast linear interpolation routine
% Usage:
% yi = interp1_scal(x,y,xi)
% where x and y are column vectors with n elements, xi is a scalar
% and yi is a scalar
% Input Arguments
% x – Sample points
% column vector
% Y – Sample data
% column vector
% xi – Query point
% scalar
function yi = interp1_scal(x,y,xi)
n = size(x,1);
j = locate(x,xi);
j = max(min(j,n-1),1);
slope = (y(j+1)-y(j))/(x(j+1)-x(j));
yi = y(j)+(xi-x(j))*slope;
end %end function interp1_scal
function jl = locate(xx,x)
%function jl = locate(xx,x)
%
% x is between xx(jl) and xx(jl+1)
%
% jl = 0 and jl = n means x is out of range
%
% xx is assumed to be monotone increasing
n = length(xx);
if x<xx(1)
jl = 0;
elseif x>xx(n)
jl = n;
else
jl = 1;
ju = n;
while (ju-jl>1)
jm = floor((ju+jl)/2);
if x>=xx(jm)
jl = jm;
else
ju=jm;
end
end
end
end %end function locate I wrote a MWE to compare the perforance of interp1 (MATLAB built-in) with my custom interp1_scal (for linear interpolation), using a simple dynamic programming problem solved with value function iteration
$$ V(k) = max_{k’} log(k^alpha-k’)+beta*V(k’) $$
Question 1: I am a bit surprised that the custom interpolation routine I wrote is much faster than the built-in interp1 for linear interpolation (on my laptop with R2024b, it is 4 times faster, here (RUN button) the speed advantage is smaller but still significant). To find the location of the query point xi on the x grid, I am using binary search (see function locate), directly translated from an older Fortran/C routine.
Question 2: Am I using interp1 in the wrong way? would using griddedInterp or other Matlab routines significantly improve run times of this MWE?
Any help, suggestions or comments is greatly appreciated!
P.S. I am glad to provide additional info on the dynamic programming problem that this simple MWE is meant to caputure in few lines of code, if someone asks for.
Minimum Working Example here:
clear,clc,close all
%% Parameters
maxit = 50;
tol = 1e-5;
alpha = 0.33;
beta = 0.96;
k_ss = (alpha * beta)^(1 / (1 – alpha));
n_k = 300;
k_min = 0.5 * k_ss;
k_max = 1.5 * k_ss;
k_grid = linspace(k_min, k_max, n_k)’;
% Precompute output y = k^alpha
y_grid = k_grid .^ alpha;
%% Method 1: value function iteration with Matlab built-in interpolation
tic
% Initialization
V0 = zeros(n_k, 1);
V1 = zeros(n_k, 1);
% Value Function Iteration
for iter=1:maxit
for i = 1:n_k
y_val = y_grid(i);
k_max_now = min(y_val, k_max); % upper bound for Brent minimization
% Objective function (negative value for minimization)
obj = @(kp) -(log(y_val-kp) + beta*interp1(k_grid,V0,kp,’linear’));
% Optimal policy
kp_opt = fminbnd(obj, k_min, k_max_now);
% Updated value function
V1(i) = -obj(kp_opt);
end
% Convergence check
err = max(abs(V1 – V0));
V0 = V1;
end %end iter
time_vfi1=toc;
%% Method 2: value function iteration with *custom* interpolation
tic
% Initialization
V0 = zeros(n_k, 1);
V2 = zeros(n_k, 1);
% Value Function Iteration
for iter=1:maxit
for i_k = 1:n_k
y_val = y_grid(i_k);
k_max_now = min(y_val, k_max);
% Objective function (negative value for minimization)
obj = @(kp) -( log(y_val-kp) + beta*interp1_scal(k_grid,V0,kp) );
% Optimal policy
kp_opt = fminbnd(obj, k_min, k_max_now);
% Updated value function
V2(i_k) = -obj(kp_opt);
end
% Convergence check
err = max(abs(V2 – V0));
V0 = V2;
end %end iter
time_vfi2=toc;
%% Compare vfi1 and vfi2
err_V = max(abs(V1-V2));
disp(‘RESULTS OF COMPARISON’)
fprintf(‘||V1-V2|| = %f n’,err_V)
fprintf(‘Run time of vfi1 with Matlab interp = %f n’,time_vfi1)
fprintf(‘Run time of vfi2 with custom interp = %f n’,time_vfi2)
fprintf(‘time vfi1 / time_vfi2 = %f n’,time_vfi1/time_vfi2)
%% Plot value function
figure;
plot(k_grid, V1, ‘LineWidth’, 1.5);
hold on
plot(k_grid, V2, ‘LineWidth’, 1.5);
legend(‘V1′,’V2’)
xlabel(‘Current capital’);
grid on;
% Fast linear interpolation routine
% Usage:
% yi = interp1_scal(x,y,xi)
% where x and y are column vectors with n elements, xi is a scalar
% and yi is a scalar
% Input Arguments
% x – Sample points
% column vector
% Y – Sample data
% column vector
% xi – Query point
% scalar
function yi = interp1_scal(x,y,xi)
n = size(x,1);
j = locate(x,xi);
j = max(min(j,n-1),1);
slope = (y(j+1)-y(j))/(x(j+1)-x(j));
yi = y(j)+(xi-x(j))*slope;
end %end function interp1_scal
function jl = locate(xx,x)
%function jl = locate(xx,x)
%
% x is between xx(jl) and xx(jl+1)
%
% jl = 0 and jl = n means x is out of range
%
% xx is assumed to be monotone increasing
n = length(xx);
if x<xx(1)
jl = 0;
elseif x>xx(n)
jl = n;
else
jl = 1;
ju = n;
while (ju-jl>1)
jm = floor((ju+jl)/2);
if x>=xx(jm)
jl = jm;
else
ju=jm;
end
end
end
end %end function locate interp1, linear interpolation MATLAB Answers — New Questions
How to generate orthogonal X-ray Projection, Digitally Reconstructed Radiographs (DRR), from a particular CT volume
Hello everyone,
I am simulating Orthogonal X-ray Projection, specifically Digitally Reconstructed Radiographs (DRR), from a particular CT volume.
To accomplish this, I first created a CT volume and then used the "generateOptimizedXrayProjections" function to produce DRR for both the anteroposterior (AP) and lateral projections.
1. To view the results from this process, please refer to lines 34-35 and line 53. When I run this simulation, I can see the DRR results.
2. However, when I used a real CT image (lines 38-39 and line 54), the generated DRR appeared completely dark.
My goal is to generate a DRR from a real CT image, such as CT_13.nii.gz.
I would greatly appreciate any insights or suggestions regarding this code.
Attached below are the MATLAB code (zip file) for reference.
Thank you!Hello everyone,
I am simulating Orthogonal X-ray Projection, specifically Digitally Reconstructed Radiographs (DRR), from a particular CT volume.
To accomplish this, I first created a CT volume and then used the "generateOptimizedXrayProjections" function to produce DRR for both the anteroposterior (AP) and lateral projections.
1. To view the results from this process, please refer to lines 34-35 and line 53. When I run this simulation, I can see the DRR results.
2. However, when I used a real CT image (lines 38-39 and line 54), the generated DRR appeared completely dark.
My goal is to generate a DRR from a real CT image, such as CT_13.nii.gz.
I would greatly appreciate any insights or suggestions regarding this code.
Attached below are the MATLAB code (zip file) for reference.
Thank you! Hello everyone,
I am simulating Orthogonal X-ray Projection, specifically Digitally Reconstructed Radiographs (DRR), from a particular CT volume.
To accomplish this, I first created a CT volume and then used the "generateOptimizedXrayProjections" function to produce DRR for both the anteroposterior (AP) and lateral projections.
1. To view the results from this process, please refer to lines 34-35 and line 53. When I run this simulation, I can see the DRR results.
2. However, when I used a real CT image (lines 38-39 and line 54), the generated DRR appeared completely dark.
My goal is to generate a DRR from a real CT image, such as CT_13.nii.gz.
I would greatly appreciate any insights or suggestions regarding this code.
Attached below are the MATLAB code (zip file) for reference.
Thank you! drr, digitally reconstructed radiographs, x-ray projection MATLAB Answers — New Questions
Where to find the default HDL project for ZedBoard or ZCU102 FMCOMMS2/3/4 Xilinx Zynq-Based Radio Linux image?
Hi,
The Communications Toolbox Support Package for Xilinx Zynq-Based Radio uses a default operating system image, which is written to the SD card during the Hardware Setup process.
My question is: where can I find the HDL Coder (or Vivado) project that generates the same FPGA bitstream (system.bit) used in this default Linux image?
More specifically, I am looking for a MATLAB/HDL-based reference project that produces exactly the same bitstream as the one included in the prebuilt Linux image provided by the support package, and then I can program my target with that.
Is this reference HDL project available to users?
If not, is there documentation describing how the default bitstream was generated and how to reproduce it?
Thank you.Hi,
The Communications Toolbox Support Package for Xilinx Zynq-Based Radio uses a default operating system image, which is written to the SD card during the Hardware Setup process.
My question is: where can I find the HDL Coder (or Vivado) project that generates the same FPGA bitstream (system.bit) used in this default Linux image?
More specifically, I am looking for a MATLAB/HDL-based reference project that produces exactly the same bitstream as the one included in the prebuilt Linux image provided by the support package, and then I can program my target with that.
Is this reference HDL project available to users?
If not, is there documentation describing how the default bitstream was generated and how to reproduce it?
Thank you. Hi,
The Communications Toolbox Support Package for Xilinx Zynq-Based Radio uses a default operating system image, which is written to the SD card during the Hardware Setup process.
My question is: where can I find the HDL Coder (or Vivado) project that generates the same FPGA bitstream (system.bit) used in this default Linux image?
More specifically, I am looking for a MATLAB/HDL-based reference project that produces exactly the same bitstream as the one included in the prebuilt Linux image provided by the support package, and then I can program my target with that.
Is this reference HDL project available to users?
If not, is there documentation describing how the default bitstream was generated and how to reproduce it?
Thank you. hdl coder, zcu102, xilinx based readio, fcomms2 MATLAB Answers — New Questions
How to run “Use FPGA I/O to Communicate with FPGA” example in a repetitive For-Loop?
Hi,
For the example “Use FPGA I/O to Communicate with FPGA”, I followed all the documented steps exactly. I was able to generate the bitstream for the ZCU102 with FMCOM2/3 and successfully program the board using the generated bitstream.
Next, I copied the MATLAB code from the example page and ran it to transmit and receive a chirp signal using RF loopback. I can observe both the TX and RX power correctly. When I run the code a single time, it works as expected and I obtain the correct input and output signals.
However, I need to run this example inside a for-loop to transmit and receive data multiple times. I understand that on the rising edge of the "txStart" signal, TVALID pulses are generated on both the TX and RX sides. In the for-loop, the start signal is toggled by writing 1 and then 0, and the stream write and stream read operations are also executed.
I have tried different combinations of toggling the start signal and performing the stream read/write operations, but the behavior is not correct. Specifically, only one out of every three iterations receives the data correctly. you can find attached one of the multiple codes that I tried.
Could you please provide a MATLAB .m script that works correctly with this example when executed inside a for-loop? Are you able to send and receive data properly multiple times?
Thanks.Hi,
For the example “Use FPGA I/O to Communicate with FPGA”, I followed all the documented steps exactly. I was able to generate the bitstream for the ZCU102 with FMCOM2/3 and successfully program the board using the generated bitstream.
Next, I copied the MATLAB code from the example page and ran it to transmit and receive a chirp signal using RF loopback. I can observe both the TX and RX power correctly. When I run the code a single time, it works as expected and I obtain the correct input and output signals.
However, I need to run this example inside a for-loop to transmit and receive data multiple times. I understand that on the rising edge of the "txStart" signal, TVALID pulses are generated on both the TX and RX sides. In the for-loop, the start signal is toggled by writing 1 and then 0, and the stream write and stream read operations are also executed.
I have tried different combinations of toggling the start signal and performing the stream read/write operations, but the behavior is not correct. Specifically, only one out of every three iterations receives the data correctly. you can find attached one of the multiple codes that I tried.
Could you please provide a MATLAB .m script that works correctly with this example when executed inside a for-loop? Are you able to send and receive data properly multiple times?
Thanks. Hi,
For the example “Use FPGA I/O to Communicate with FPGA”, I followed all the documented steps exactly. I was able to generate the bitstream for the ZCU102 with FMCOM2/3 and successfully program the board using the generated bitstream.
Next, I copied the MATLAB code from the example page and ran it to transmit and receive a chirp signal using RF loopback. I can observe both the TX and RX power correctly. When I run the code a single time, it works as expected and I obtain the correct input and output signals.
However, I need to run this example inside a for-loop to transmit and receive data multiple times. I understand that on the rising edge of the "txStart" signal, TVALID pulses are generated on both the TX and RX sides. In the for-loop, the start signal is toggled by writing 1 and then 0, and the stream write and stream read operations are also executed.
I have tried different combinations of toggling the start signal and performing the stream read/write operations, but the behavior is not correct. Specifically, only one out of every three iterations receives the data correctly. you can find attached one of the multiple codes that I tried.
Could you please provide a MATLAB .m script that works correctly with this example when executed inside a for-loop? Are you able to send and receive data properly multiple times?
Thanks. hdl coder, zcu102, fmcomm2 MATLAB Answers — New Questions
How Does interp1 Work if the Sample Points are not Monotonic?
Forever I’ve thought that the sample points input to @doc:interp1 have to be distinct AND monotonic. But I just saw on the doc page that distinct is the only requirement.
For example:
matlabRelease
x = [1,3,0,2]; % not monotonic
y = sin(x);
xq = 1.5;
yi = interp1(x,y,xq)
I’m quite surprised by this result.
Does interp1 sort the sample points and reorder the sample values if the sample points are not monotonic?
The same answer is obtained:
isequal(yi,interp1(sort(x),sin(sort(x)),xq))Forever I’ve thought that the sample points input to @doc:interp1 have to be distinct AND monotonic. But I just saw on the doc page that distinct is the only requirement.
For example:
matlabRelease
x = [1,3,0,2]; % not monotonic
y = sin(x);
xq = 1.5;
yi = interp1(x,y,xq)
I’m quite surprised by this result.
Does interp1 sort the sample points and reorder the sample values if the sample points are not monotonic?
The same answer is obtained:
isequal(yi,interp1(sort(x),sin(sort(x)),xq)) Forever I’ve thought that the sample points input to @doc:interp1 have to be distinct AND monotonic. But I just saw on the doc page that distinct is the only requirement.
For example:
matlabRelease
x = [1,3,0,2]; % not monotonic
y = sin(x);
xq = 1.5;
yi = interp1(x,y,xq)
I’m quite surprised by this result.
Does interp1 sort the sample points and reorder the sample values if the sample points are not monotonic?
The same answer is obtained:
isequal(yi,interp1(sort(x),sin(sort(x)),xq)) interp1, montonic, sample points MATLAB Answers — New Questions
LaTex Font has changed since update
I want my font on my figues and tables to match the rest of what i am writing, so I ussually use the LaTex font in matlab when making figues.
In the start of the script I would write:
set(groot,’defaultAxesTickLabelInterpreter’,’latex’)
set(groot,’defaulttextinterpreter’,’latex’)
set(groot,’defaultLegendInterpreter’,’latex’)
However, since I hav updated my MatLab to R2023b, the font has changed.
I have attached eksample of how it looked before and after the update.
Granted symbols like and sub- and superscrpts still work as it ussually did.I want my font on my figues and tables to match the rest of what i am writing, so I ussually use the LaTex font in matlab when making figues.
In the start of the script I would write:
set(groot,’defaultAxesTickLabelInterpreter’,’latex’)
set(groot,’defaulttextinterpreter’,’latex’)
set(groot,’defaultLegendInterpreter’,’latex’)
However, since I hav updated my MatLab to R2023b, the font has changed.
I have attached eksample of how it looked before and after the update.
Granted symbols like and sub- and superscrpts still work as it ussually did. I want my font on my figues and tables to match the rest of what i am writing, so I ussually use the LaTex font in matlab when making figues.
In the start of the script I would write:
set(groot,’defaultAxesTickLabelInterpreter’,’latex’)
set(groot,’defaulttextinterpreter’,’latex’)
set(groot,’defaultLegendInterpreter’,’latex’)
However, since I hav updated my MatLab to R2023b, the font has changed.
I have attached eksample of how it looked before and after the update.
Granted symbols like and sub- and superscrpts still work as it ussually did. latex, font, r2023b MATLAB Answers — New Questions
When i close a scope in simulink on my apple silicon the windows switches from simulink to matlab.
Whenever i try to close my scope in simulink, the window enters matlab instead of simulink where i originaly was. This causes me to switch back to simulink everytime i need to check results.Whenever i try to close my scope in simulink, the window enters matlab instead of simulink where i originaly was. This causes me to switch back to simulink everytime i need to check results. Whenever i try to close my scope in simulink, the window enters matlab instead of simulink where i originaly was. This causes me to switch back to simulink everytime i need to check results. simulink MATLAB Answers — New Questions
Edges and Observed values of Chi2gof
I am trying to do a chi squared test on the means of this data which I have already sorted and is not the issue here. However, my observed values are just 4 ones even though I inputted the means I calculated. Does anyone know why this happens and how to solve it? Your help would be appreciated.
a=readmatrix("DIP Project- Population.xlsx");
population=a(:,1);
production=a(:,7);
gr1gen36=a(61:90,7);
gr1gen36(isnan(gr1gen36))=0;
gr1gen36;
m1=mean(gr1gen36);
gr2gen36=a(151:180,7);
gr2gen36(isnan(gr2gen36))=0;
gr2gen36;
m2=mean(gr2gen36);
gr3gen36=a(241:270,7);
gr3gen36(isnan(gr3gen36))=0;
m3=mean(gr3gen36);
gr4gen36=a(331:360,7);
gr4gen36(isnan(gr4gen36))=0;
gr4gen36;
m4=mean(gr4gen36);
gen36=[m1,m2,m3,m4];
expected=mean(gen36);
ex=[expected,expected,expected,expected];
[h,p,tbl]=chi2gof(gen36,’Expected’,ex,’Alpha’,0.05)
tbl =
struct with fields:
chi2stat: 66.0168
df: 3
edges: [9.3667 13.5667 17.7667 21.9667 26.1667]
O: [1 1 1 1]
E: [18.4500 18.4500 18.4500 18.4500]I am trying to do a chi squared test on the means of this data which I have already sorted and is not the issue here. However, my observed values are just 4 ones even though I inputted the means I calculated. Does anyone know why this happens and how to solve it? Your help would be appreciated.
a=readmatrix("DIP Project- Population.xlsx");
population=a(:,1);
production=a(:,7);
gr1gen36=a(61:90,7);
gr1gen36(isnan(gr1gen36))=0;
gr1gen36;
m1=mean(gr1gen36);
gr2gen36=a(151:180,7);
gr2gen36(isnan(gr2gen36))=0;
gr2gen36;
m2=mean(gr2gen36);
gr3gen36=a(241:270,7);
gr3gen36(isnan(gr3gen36))=0;
m3=mean(gr3gen36);
gr4gen36=a(331:360,7);
gr4gen36(isnan(gr4gen36))=0;
gr4gen36;
m4=mean(gr4gen36);
gen36=[m1,m2,m3,m4];
expected=mean(gen36);
ex=[expected,expected,expected,expected];
[h,p,tbl]=chi2gof(gen36,’Expected’,ex,’Alpha’,0.05)
tbl =
struct with fields:
chi2stat: 66.0168
df: 3
edges: [9.3667 13.5667 17.7667 21.9667 26.1667]
O: [1 1 1 1]
E: [18.4500 18.4500 18.4500 18.4500] I am trying to do a chi squared test on the means of this data which I have already sorted and is not the issue here. However, my observed values are just 4 ones even though I inputted the means I calculated. Does anyone know why this happens and how to solve it? Your help would be appreciated.
a=readmatrix("DIP Project- Population.xlsx");
population=a(:,1);
production=a(:,7);
gr1gen36=a(61:90,7);
gr1gen36(isnan(gr1gen36))=0;
gr1gen36;
m1=mean(gr1gen36);
gr2gen36=a(151:180,7);
gr2gen36(isnan(gr2gen36))=0;
gr2gen36;
m2=mean(gr2gen36);
gr3gen36=a(241:270,7);
gr3gen36(isnan(gr3gen36))=0;
m3=mean(gr3gen36);
gr4gen36=a(331:360,7);
gr4gen36(isnan(gr4gen36))=0;
gr4gen36;
m4=mean(gr4gen36);
gen36=[m1,m2,m3,m4];
expected=mean(gen36);
ex=[expected,expected,expected,expected];
[h,p,tbl]=chi2gof(gen36,’Expected’,ex,’Alpha’,0.05)
tbl =
struct with fields:
chi2stat: 66.0168
df: 3
edges: [9.3667 13.5667 17.7667 21.9667 26.1667]
O: [1 1 1 1]
E: [18.4500 18.4500 18.4500 18.4500] statistics MATLAB Answers — New Questions
why can I only edit one script?
Somehow I have reset Matlab to that I can only edit one script at a time. Can you suggest what I am doing wrong? Thanks.Somehow I have reset Matlab to that I can only edit one script at a time. Can you suggest what I am doing wrong? Thanks. Somehow I have reset Matlab to that I can only edit one script at a time. Can you suggest what I am doing wrong? Thanks. editor MATLAB Answers — New Questions
Perfusionist nurse trying to lear fluids mechanics
Hello everyone;
I am an Spanish nurse studying a postdegree of Extracorporeal Circulation on Cardiac Surgery and now we are studying phisiology and fluids mechanics and i discorver my university has license with matlab and i would like to learn about my field simulating on this software. Anyone has any tip how start, if vaible simulate an oxiygen membrane etc
Thank you everybody.Hello everyone;
I am an Spanish nurse studying a postdegree of Extracorporeal Circulation on Cardiac Surgery and now we are studying phisiology and fluids mechanics and i discorver my university has license with matlab and i would like to learn about my field simulating on this software. Anyone has any tip how start, if vaible simulate an oxiygen membrane etc
Thank you everybody. Hello everyone;
I am an Spanish nurse studying a postdegree of Extracorporeal Circulation on Cardiac Surgery and now we are studying phisiology and fluids mechanics and i discorver my university has license with matlab and i would like to learn about my field simulating on this software. Anyone has any tip how start, if vaible simulate an oxiygen membrane etc
Thank you everybody. medicine MATLAB Answers — New Questions
Why does joint PID tracking in a Simscape Multibody leg model degrade when Spatial Contact Force is enabled, while it works well without ground contact (XZ plane)?
I am simulating a simplified lower-limb / prosthetic leg in Simscape Multibody with 3 revolute joints (hip, knee, ankle). The motion is intended to be planar in the sagittal plane (XZ).What I am doing
I provide reference joint trajectories for hip/knee/ankle from a gait dataset (10 concatenated gait cycles) using three timeseries signals:
hip_ts, knee_ts, ankle_ts
Each joint is controlled by a joint-level PID/PD block that outputs a torque
The measured joint angles q are taken from the joint sensors and fed back to the controller (scopes show reference vs simulated for each joint).
What works (no contact)
If I disable ground contact, the joint tracking is reasonably good for all joints (hip/knee/ankle). The simulated angles follow the reference signals with small error.
The problem (with contact enabled)
When I enable foot–ground contact using Spatial Contact Force (foot geometry vs ground plane), the tracking becomes much worse:
large tracking errors / oscillations appear
the behavior looks unstable or heavily disturbed during stance/contact phases
the same PID gains that work without contact no longer work
What I suspect / questions
I am trying to understand what is causing this degradation when contact is enabled:
Is this mainly due to the contact model parameters (stiffness, damping, friction) creating stiff dynamics that destabilize the joint PID?
Could the issue be caused by unintended extra DOFs at the hip/base (e.g., the hip not fully constrained in the plane), so contact forces introduce out-of-plane motion or additional dynamics?
Is it conceptually wrong to expect simple joint PID tracking to work well when contact forces are present, and should I instead use:
impedance control at the joints,
inverse dynamics / computed torque,
or a constraint-based approach for stance?
What I can provide
Screenshot of the Simulink/Simscape model (joint controllers + Spatial Contact Force block)
Scope screenshots showing reference vs actual joint angles for hip/knee/ankle
Contact block settings (stiffness/damping/friction) and solver settings if needed
Question: What are the most common reasons why enabling Spatial Contact Force makes joint-level PID tracking degrade dramatically in Simscape Multibody, and what specific checks/changes would you recommend (contact parameters, solver, constraints/DOFs at hip/base, control structure)?I am simulating a simplified lower-limb / prosthetic leg in Simscape Multibody with 3 revolute joints (hip, knee, ankle). The motion is intended to be planar in the sagittal plane (XZ).What I am doing
I provide reference joint trajectories for hip/knee/ankle from a gait dataset (10 concatenated gait cycles) using three timeseries signals:
hip_ts, knee_ts, ankle_ts
Each joint is controlled by a joint-level PID/PD block that outputs a torque
The measured joint angles q are taken from the joint sensors and fed back to the controller (scopes show reference vs simulated for each joint).
What works (no contact)
If I disable ground contact, the joint tracking is reasonably good for all joints (hip/knee/ankle). The simulated angles follow the reference signals with small error.
The problem (with contact enabled)
When I enable foot–ground contact using Spatial Contact Force (foot geometry vs ground plane), the tracking becomes much worse:
large tracking errors / oscillations appear
the behavior looks unstable or heavily disturbed during stance/contact phases
the same PID gains that work without contact no longer work
What I suspect / questions
I am trying to understand what is causing this degradation when contact is enabled:
Is this mainly due to the contact model parameters (stiffness, damping, friction) creating stiff dynamics that destabilize the joint PID?
Could the issue be caused by unintended extra DOFs at the hip/base (e.g., the hip not fully constrained in the plane), so contact forces introduce out-of-plane motion or additional dynamics?
Is it conceptually wrong to expect simple joint PID tracking to work well when contact forces are present, and should I instead use:
impedance control at the joints,
inverse dynamics / computed torque,
or a constraint-based approach for stance?
What I can provide
Screenshot of the Simulink/Simscape model (joint controllers + Spatial Contact Force block)
Scope screenshots showing reference vs actual joint angles for hip/knee/ankle
Contact block settings (stiffness/damping/friction) and solver settings if needed
Question: What are the most common reasons why enabling Spatial Contact Force makes joint-level PID tracking degrade dramatically in Simscape Multibody, and what specific checks/changes would you recommend (contact parameters, solver, constraints/DOFs at hip/base, control structure)? I am simulating a simplified lower-limb / prosthetic leg in Simscape Multibody with 3 revolute joints (hip, knee, ankle). The motion is intended to be planar in the sagittal plane (XZ).What I am doing
I provide reference joint trajectories for hip/knee/ankle from a gait dataset (10 concatenated gait cycles) using three timeseries signals:
hip_ts, knee_ts, ankle_ts
Each joint is controlled by a joint-level PID/PD block that outputs a torque
The measured joint angles q are taken from the joint sensors and fed back to the controller (scopes show reference vs simulated for each joint).
What works (no contact)
If I disable ground contact, the joint tracking is reasonably good for all joints (hip/knee/ankle). The simulated angles follow the reference signals with small error.
The problem (with contact enabled)
When I enable foot–ground contact using Spatial Contact Force (foot geometry vs ground plane), the tracking becomes much worse:
large tracking errors / oscillations appear
the behavior looks unstable or heavily disturbed during stance/contact phases
the same PID gains that work without contact no longer work
What I suspect / questions
I am trying to understand what is causing this degradation when contact is enabled:
Is this mainly due to the contact model parameters (stiffness, damping, friction) creating stiff dynamics that destabilize the joint PID?
Could the issue be caused by unintended extra DOFs at the hip/base (e.g., the hip not fully constrained in the plane), so contact forces introduce out-of-plane motion or additional dynamics?
Is it conceptually wrong to expect simple joint PID tracking to work well when contact forces are present, and should I instead use:
impedance control at the joints,
inverse dynamics / computed torque,
or a constraint-based approach for stance?
What I can provide
Screenshot of the Simulink/Simscape model (joint controllers + Spatial Contact Force block)
Scope screenshots showing reference vs actual joint angles for hip/knee/ankle
Contact block settings (stiffness/damping/friction) and solver settings if needed
Question: What are the most common reasons why enabling Spatial Contact Force makes joint-level PID tracking degrade dramatically in Simscape Multibody, and what specific checks/changes would you recommend (contact parameters, solver, constraints/DOFs at hip/base, control structure)? simulink, simscape, control MATLAB Answers — New Questions
Please help me to run this simple code
% Error
Array indices must be positive integers or logical values.
Error in Untitled2 (line 45)
kh=kf*((k1+2*kf-2*ph1(kf-k1))/(k1+2*kf+ph1*(kf-k1)));
% code
proj()
function sol = proj
clc; clf; clear;
rhof=997.1*10^-3;kf=0.613*10^5;cpf=4179*10^4;muf=10^-3*10;
alfaf=kf/(rhof*cpf);
bef=21*10^-5;
sigf=0.05*10^-8;
ky=muf/rhof;
%Titanium oxide
ph4=0.01;
rho4=4250*10^-3;
cp4=711*10^4;
k4=8.953*10^5;
sig4=2.6*10*10^-1;
%Ag
ph1=0.01;
rho1=10500*10^-3;
cp1=235*10^4;
k1=429*10^5;be1=21*10^-5;
sig1=0.74*10^-2;
%copper
ph2=0.01;
rho2=8933*10^-3;
cp2=385*10^4;
k2=400*10^5;
sig2=5.96*10^-1;
be2=1.67*10^-5;
%Alumina
ph3=0.01;
rho3=3970*10^-3;
cp3=765*10^4;
k3=40*10^5;
be3=0.85*10^-5;
sig3=3.5*10^-1;
%Relation of ternary hyprid
kh=kf*((k1+2*kf-2*ph1(kf-k1))/(k1+2*kf+ph1*(kf-k1)));
kh=kn*((k2+2*kn-2*ph2(kn-k2))/(k2+2*kn+ph2*(kn-k2)));
kt=kh*((k3+2*kh-2*ph3(kh-k3))/(k3+2*kh+ph3*(kh-k3)));
kT=kt*((k4+2*kt-2*ph4*(kt-k4))/(k4+2*kt+ph4*(kt-k4)));
muT= muf/((1-ph1)^2.5*(1-ph2)^2.5*(1-ph3)^2.5*(1-ph4)^2.5);
rhoT=rhof*((1-ph4)*((1-ph3)*((1-ph2)*((1-ph1)+ph1*((ph1*rho1*(1/rhof))))+(ph2*rho2*(1/rhof))))+(ph3*rho3*(1/rhof))+ph4*rho4*(1/rhof));
sign = sigf*(1+(3*(sigf-1)*ph1)/((sigf+2)-(sigf-1)*ph1));
sigh = sign*(1+(3*(sign-1)*ph2)/((sign+2)-(sign-1)*ph2));
sigt = sigh*(1+(3*(sigh-1)*ph3)/((sigh+2)-(sigh-1)*ph3));
sigT = sigt*(1+(3*(sigt-1)*ph4)/((sigt+2)-(sigt-1)*ph4));
%vt=rhot*cpt
VT=(rhof*cpf)*((1-ph4)*((1-ph3)*((1-ph2)*((1-ph1)+ph1*((ph1*cp1*(1/rhof*cpf))))+(ph2*cp2*(1/rhof*cpf))))+(ph3*cp3*(1/rhof*cpf))+ph4*cp4*(1/rhof*cpf));
%disp(‘vt’);disp(vt);
%vb=rho*betb
vT =(1-ph1)*((1-ph2)*((1-ph3)+ph3*((rho3*be3)/(rhof*bef)))+ph2*((rho2*be2)/(rhof*bef)))+(1-ph1)*ph1*((rho1*be1)/(rhof*bef));
myLegend1 = {};myLegend2 = {};
rr = [0.1 0.3 0.5 0.7]
for i =1:numel(rr)
Rd= rr(i)
M=0.5;
R=1;Pr=6.9;
m = linspace(0,1);
y0 = [0,1,0,1,0,0,0,0];options =bvpset(‘stats’,’on’,’RelTol’,1e-5);
solinit = bvpinit(m,y0);
sol= bvp4c(@projfun,@projbc,solinit,options);
figure(1)
plot(sol.x,(sol.y(1,:)))
grid on,hold on
myLegend1{i}=[‘n= ‘,num2str(rr(i))];
figure(2)
plot(sol.x,(sol.y(7,:)))
grid on,hold on
myLegend2{i}=[‘n= ‘,num2str(rr(i))];
i=i+1;
end
figure(1)
legend(myLegend1)
hold on
figure(2)
legend(myLegend2)
hold on
function dy = projfun(x, y)
dy= zeros(8,1);
% alignComments
f = y(1);
df = y(2);
g = y(3);
dg= y(4);
h= y(5);
dh = y(6);
t = y(7);
dt=y(8);
dy(1) = df;
dy(2) =(1/(1+x^2))*(3*x*df+R*((muT/muf))*(f^2-f*df+h*df-g^2+(sigT/sigf)*M*f));
dy(3) = dg;
dy(4) = (1/(1+x^2))*(3*x*dg+R*((muT/muf))*(2*f*g-f*dg+h*dg+(sigT/sigf)*M*g));
dy(5) =dh ;
dy(6) =(1/(1+x^2))*(2*x*dh-h+R*((muT/muf))*(f*dh-h*dh-f*h));
dy(7) =dt;
dy(8)=(1/(1+x^2+(4/3)*Rd*(1/(kT/kf))))*(((x-4)*dt)-4*t-Pr*R*((vT/(rhof*cpf))*(kf/kT))*(x*f*dt-2*f*t-h*dt));
end
end
function res= projbc(ya,yb)
res= [ya(1)-0.1;
ya(3)-1;
ya(5)-0.1;
ya(7)-1;
yb(1)-0.1;
yb(3);
yb(5);
yb(7);
];
end% Error
Array indices must be positive integers or logical values.
Error in Untitled2 (line 45)
kh=kf*((k1+2*kf-2*ph1(kf-k1))/(k1+2*kf+ph1*(kf-k1)));
% code
proj()
function sol = proj
clc; clf; clear;
rhof=997.1*10^-3;kf=0.613*10^5;cpf=4179*10^4;muf=10^-3*10;
alfaf=kf/(rhof*cpf);
bef=21*10^-5;
sigf=0.05*10^-8;
ky=muf/rhof;
%Titanium oxide
ph4=0.01;
rho4=4250*10^-3;
cp4=711*10^4;
k4=8.953*10^5;
sig4=2.6*10*10^-1;
%Ag
ph1=0.01;
rho1=10500*10^-3;
cp1=235*10^4;
k1=429*10^5;be1=21*10^-5;
sig1=0.74*10^-2;
%copper
ph2=0.01;
rho2=8933*10^-3;
cp2=385*10^4;
k2=400*10^5;
sig2=5.96*10^-1;
be2=1.67*10^-5;
%Alumina
ph3=0.01;
rho3=3970*10^-3;
cp3=765*10^4;
k3=40*10^5;
be3=0.85*10^-5;
sig3=3.5*10^-1;
%Relation of ternary hyprid
kh=kf*((k1+2*kf-2*ph1(kf-k1))/(k1+2*kf+ph1*(kf-k1)));
kh=kn*((k2+2*kn-2*ph2(kn-k2))/(k2+2*kn+ph2*(kn-k2)));
kt=kh*((k3+2*kh-2*ph3(kh-k3))/(k3+2*kh+ph3*(kh-k3)));
kT=kt*((k4+2*kt-2*ph4*(kt-k4))/(k4+2*kt+ph4*(kt-k4)));
muT= muf/((1-ph1)^2.5*(1-ph2)^2.5*(1-ph3)^2.5*(1-ph4)^2.5);
rhoT=rhof*((1-ph4)*((1-ph3)*((1-ph2)*((1-ph1)+ph1*((ph1*rho1*(1/rhof))))+(ph2*rho2*(1/rhof))))+(ph3*rho3*(1/rhof))+ph4*rho4*(1/rhof));
sign = sigf*(1+(3*(sigf-1)*ph1)/((sigf+2)-(sigf-1)*ph1));
sigh = sign*(1+(3*(sign-1)*ph2)/((sign+2)-(sign-1)*ph2));
sigt = sigh*(1+(3*(sigh-1)*ph3)/((sigh+2)-(sigh-1)*ph3));
sigT = sigt*(1+(3*(sigt-1)*ph4)/((sigt+2)-(sigt-1)*ph4));
%vt=rhot*cpt
VT=(rhof*cpf)*((1-ph4)*((1-ph3)*((1-ph2)*((1-ph1)+ph1*((ph1*cp1*(1/rhof*cpf))))+(ph2*cp2*(1/rhof*cpf))))+(ph3*cp3*(1/rhof*cpf))+ph4*cp4*(1/rhof*cpf));
%disp(‘vt’);disp(vt);
%vb=rho*betb
vT =(1-ph1)*((1-ph2)*((1-ph3)+ph3*((rho3*be3)/(rhof*bef)))+ph2*((rho2*be2)/(rhof*bef)))+(1-ph1)*ph1*((rho1*be1)/(rhof*bef));
myLegend1 = {};myLegend2 = {};
rr = [0.1 0.3 0.5 0.7]
for i =1:numel(rr)
Rd= rr(i)
M=0.5;
R=1;Pr=6.9;
m = linspace(0,1);
y0 = [0,1,0,1,0,0,0,0];options =bvpset(‘stats’,’on’,’RelTol’,1e-5);
solinit = bvpinit(m,y0);
sol= bvp4c(@projfun,@projbc,solinit,options);
figure(1)
plot(sol.x,(sol.y(1,:)))
grid on,hold on
myLegend1{i}=[‘n= ‘,num2str(rr(i))];
figure(2)
plot(sol.x,(sol.y(7,:)))
grid on,hold on
myLegend2{i}=[‘n= ‘,num2str(rr(i))];
i=i+1;
end
figure(1)
legend(myLegend1)
hold on
figure(2)
legend(myLegend2)
hold on
function dy = projfun(x, y)
dy= zeros(8,1);
% alignComments
f = y(1);
df = y(2);
g = y(3);
dg= y(4);
h= y(5);
dh = y(6);
t = y(7);
dt=y(8);
dy(1) = df;
dy(2) =(1/(1+x^2))*(3*x*df+R*((muT/muf))*(f^2-f*df+h*df-g^2+(sigT/sigf)*M*f));
dy(3) = dg;
dy(4) = (1/(1+x^2))*(3*x*dg+R*((muT/muf))*(2*f*g-f*dg+h*dg+(sigT/sigf)*M*g));
dy(5) =dh ;
dy(6) =(1/(1+x^2))*(2*x*dh-h+R*((muT/muf))*(f*dh-h*dh-f*h));
dy(7) =dt;
dy(8)=(1/(1+x^2+(4/3)*Rd*(1/(kT/kf))))*(((x-4)*dt)-4*t-Pr*R*((vT/(rhof*cpf))*(kf/kT))*(x*f*dt-2*f*t-h*dt));
end
end
function res= projbc(ya,yb)
res= [ya(1)-0.1;
ya(3)-1;
ya(5)-0.1;
ya(7)-1;
yb(1)-0.1;
yb(3);
yb(5);
yb(7);
];
end % Error
Array indices must be positive integers or logical values.
Error in Untitled2 (line 45)
kh=kf*((k1+2*kf-2*ph1(kf-k1))/(k1+2*kf+ph1*(kf-k1)));
% code
proj()
function sol = proj
clc; clf; clear;
rhof=997.1*10^-3;kf=0.613*10^5;cpf=4179*10^4;muf=10^-3*10;
alfaf=kf/(rhof*cpf);
bef=21*10^-5;
sigf=0.05*10^-8;
ky=muf/rhof;
%Titanium oxide
ph4=0.01;
rho4=4250*10^-3;
cp4=711*10^4;
k4=8.953*10^5;
sig4=2.6*10*10^-1;
%Ag
ph1=0.01;
rho1=10500*10^-3;
cp1=235*10^4;
k1=429*10^5;be1=21*10^-5;
sig1=0.74*10^-2;
%copper
ph2=0.01;
rho2=8933*10^-3;
cp2=385*10^4;
k2=400*10^5;
sig2=5.96*10^-1;
be2=1.67*10^-5;
%Alumina
ph3=0.01;
rho3=3970*10^-3;
cp3=765*10^4;
k3=40*10^5;
be3=0.85*10^-5;
sig3=3.5*10^-1;
%Relation of ternary hyprid
kh=kf*((k1+2*kf-2*ph1(kf-k1))/(k1+2*kf+ph1*(kf-k1)));
kh=kn*((k2+2*kn-2*ph2(kn-k2))/(k2+2*kn+ph2*(kn-k2)));
kt=kh*((k3+2*kh-2*ph3(kh-k3))/(k3+2*kh+ph3*(kh-k3)));
kT=kt*((k4+2*kt-2*ph4*(kt-k4))/(k4+2*kt+ph4*(kt-k4)));
muT= muf/((1-ph1)^2.5*(1-ph2)^2.5*(1-ph3)^2.5*(1-ph4)^2.5);
rhoT=rhof*((1-ph4)*((1-ph3)*((1-ph2)*((1-ph1)+ph1*((ph1*rho1*(1/rhof))))+(ph2*rho2*(1/rhof))))+(ph3*rho3*(1/rhof))+ph4*rho4*(1/rhof));
sign = sigf*(1+(3*(sigf-1)*ph1)/((sigf+2)-(sigf-1)*ph1));
sigh = sign*(1+(3*(sign-1)*ph2)/((sign+2)-(sign-1)*ph2));
sigt = sigh*(1+(3*(sigh-1)*ph3)/((sigh+2)-(sigh-1)*ph3));
sigT = sigt*(1+(3*(sigt-1)*ph4)/((sigt+2)-(sigt-1)*ph4));
%vt=rhot*cpt
VT=(rhof*cpf)*((1-ph4)*((1-ph3)*((1-ph2)*((1-ph1)+ph1*((ph1*cp1*(1/rhof*cpf))))+(ph2*cp2*(1/rhof*cpf))))+(ph3*cp3*(1/rhof*cpf))+ph4*cp4*(1/rhof*cpf));
%disp(‘vt’);disp(vt);
%vb=rho*betb
vT =(1-ph1)*((1-ph2)*((1-ph3)+ph3*((rho3*be3)/(rhof*bef)))+ph2*((rho2*be2)/(rhof*bef)))+(1-ph1)*ph1*((rho1*be1)/(rhof*bef));
myLegend1 = {};myLegend2 = {};
rr = [0.1 0.3 0.5 0.7]
for i =1:numel(rr)
Rd= rr(i)
M=0.5;
R=1;Pr=6.9;
m = linspace(0,1);
y0 = [0,1,0,1,0,0,0,0];options =bvpset(‘stats’,’on’,’RelTol’,1e-5);
solinit = bvpinit(m,y0);
sol= bvp4c(@projfun,@projbc,solinit,options);
figure(1)
plot(sol.x,(sol.y(1,:)))
grid on,hold on
myLegend1{i}=[‘n= ‘,num2str(rr(i))];
figure(2)
plot(sol.x,(sol.y(7,:)))
grid on,hold on
myLegend2{i}=[‘n= ‘,num2str(rr(i))];
i=i+1;
end
figure(1)
legend(myLegend1)
hold on
figure(2)
legend(myLegend2)
hold on
function dy = projfun(x, y)
dy= zeros(8,1);
% alignComments
f = y(1);
df = y(2);
g = y(3);
dg= y(4);
h= y(5);
dh = y(6);
t = y(7);
dt=y(8);
dy(1) = df;
dy(2) =(1/(1+x^2))*(3*x*df+R*((muT/muf))*(f^2-f*df+h*df-g^2+(sigT/sigf)*M*f));
dy(3) = dg;
dy(4) = (1/(1+x^2))*(3*x*dg+R*((muT/muf))*(2*f*g-f*dg+h*dg+(sigT/sigf)*M*g));
dy(5) =dh ;
dy(6) =(1/(1+x^2))*(2*x*dh-h+R*((muT/muf))*(f*dh-h*dh-f*h));
dy(7) =dt;
dy(8)=(1/(1+x^2+(4/3)*Rd*(1/(kT/kf))))*(((x-4)*dt)-4*t-Pr*R*((vT/(rhof*cpf))*(kf/kT))*(x*f*dt-2*f*t-h*dt));
end
end
function res= projbc(ya,yb)
res= [ya(1)-0.1;
ya(3)-1;
ya(5)-0.1;
ya(7)-1;
yb(1)-0.1;
yb(3);
yb(5);
yb(7);
];
end pvp4c MATLAB Answers — New Questions
Is this Application of Leibniz Rule in Symbolic Math Toolbox Incorrect?
Referring to Leibniz Integral Rule:
Verify R2025b
matlabRelease
Define some functions
syms t x
syms f_1(x) f_2(x) g(t)
Case 1 looks correct:
syms G(x)
eqn1 = G(x) == int(g(t),t,f_1(x),f_2(x));
eqn2 = diff(eqn1,x);
case1 = [eqn1;eqn2]
Case 2 looks correct. Same as case 1 with dg(t)/dt replacing g(t).
Dg(t) = diff(g(t),t);
eqn3 = G(x) == int(Dg(t),t,f_1(x),f_2(x));
eqn4 = diff(eqn3,x);
case2 = [eqn3;eqn4]
Case 3 looks correct. Same as case 1 with g(t) = h(t)p(t)
syms h(t) p(t)
eqn5 = G(x) == int(h(t)*p(t),t,f_1(x),f_2(x));
eqn6 = diff(eqn5,x);
case3 = [eqn5;eqn6]
Case 4 looks incorrect
Dp(t) = diff(p(t),t);
eqn7 = G(x) == int(h(t)*Dp(t),t,f_1(x),f_2(x));
eqn8 = diff(eqn7,x);
case4 = [eqn7;eqn8]
I don’t understand the meaning of the third multiplicands in both terms of the derivative expression. What does it mean to differentiate with respect to a function?
Seems like case 4 should be:
eqn9 = diff(G(x),x) == h(f_2(x))*Dp(f_2(x))*diff(f_2(x),x) – h(f_1(x))*Dp(f_1(x))*diff(f_1(x),x)
Is case 4 (eqn8) incorrect or am I misunderstanding the mathematical meaning of
diff(p(f_2(x)),f_2(x))Referring to Leibniz Integral Rule:
Verify R2025b
matlabRelease
Define some functions
syms t x
syms f_1(x) f_2(x) g(t)
Case 1 looks correct:
syms G(x)
eqn1 = G(x) == int(g(t),t,f_1(x),f_2(x));
eqn2 = diff(eqn1,x);
case1 = [eqn1;eqn2]
Case 2 looks correct. Same as case 1 with dg(t)/dt replacing g(t).
Dg(t) = diff(g(t),t);
eqn3 = G(x) == int(Dg(t),t,f_1(x),f_2(x));
eqn4 = diff(eqn3,x);
case2 = [eqn3;eqn4]
Case 3 looks correct. Same as case 1 with g(t) = h(t)p(t)
syms h(t) p(t)
eqn5 = G(x) == int(h(t)*p(t),t,f_1(x),f_2(x));
eqn6 = diff(eqn5,x);
case3 = [eqn5;eqn6]
Case 4 looks incorrect
Dp(t) = diff(p(t),t);
eqn7 = G(x) == int(h(t)*Dp(t),t,f_1(x),f_2(x));
eqn8 = diff(eqn7,x);
case4 = [eqn7;eqn8]
I don’t understand the meaning of the third multiplicands in both terms of the derivative expression. What does it mean to differentiate with respect to a function?
Seems like case 4 should be:
eqn9 = diff(G(x),x) == h(f_2(x))*Dp(f_2(x))*diff(f_2(x),x) – h(f_1(x))*Dp(f_1(x))*diff(f_1(x),x)
Is case 4 (eqn8) incorrect or am I misunderstanding the mathematical meaning of
diff(p(f_2(x)),f_2(x)) Referring to Leibniz Integral Rule:
Verify R2025b
matlabRelease
Define some functions
syms t x
syms f_1(x) f_2(x) g(t)
Case 1 looks correct:
syms G(x)
eqn1 = G(x) == int(g(t),t,f_1(x),f_2(x));
eqn2 = diff(eqn1,x);
case1 = [eqn1;eqn2]
Case 2 looks correct. Same as case 1 with dg(t)/dt replacing g(t).
Dg(t) = diff(g(t),t);
eqn3 = G(x) == int(Dg(t),t,f_1(x),f_2(x));
eqn4 = diff(eqn3,x);
case2 = [eqn3;eqn4]
Case 3 looks correct. Same as case 1 with g(t) = h(t)p(t)
syms h(t) p(t)
eqn5 = G(x) == int(h(t)*p(t),t,f_1(x),f_2(x));
eqn6 = diff(eqn5,x);
case3 = [eqn5;eqn6]
Case 4 looks incorrect
Dp(t) = diff(p(t),t);
eqn7 = G(x) == int(h(t)*Dp(t),t,f_1(x),f_2(x));
eqn8 = diff(eqn7,x);
case4 = [eqn7;eqn8]
I don’t understand the meaning of the third multiplicands in both terms of the derivative expression. What does it mean to differentiate with respect to a function?
Seems like case 4 should be:
eqn9 = diff(G(x),x) == h(f_2(x))*Dp(f_2(x))*diff(f_2(x),x) – h(f_1(x))*Dp(f_1(x))*diff(f_1(x),x)
Is case 4 (eqn8) incorrect or am I misunderstanding the mathematical meaning of
diff(p(f_2(x)),f_2(x)) leibniz rule MATLAB Answers — New Questions
interp1() returns a plot with empty sections
I am trying to use the interp1() function to first, plot a continuous graph between a variable and time. Then I want to use the plot to look up the value of the variable at every instant. However, my plot appears to have empty sections, which is probably why I get NaN errors in my calculations. I attached my excel file also.
grade_data = readmatrix(‘grade.xlsx’); % reads the excel file
t_grade_raw = grade_data(:, 1)’; % Extract Time (transpose to row vector)
grade_raw = grade_data(:, 2)’; % Extract Grade (transpose to row vector)
% Interpolating to plot
grade_interp = interp1(t_grade_raw, grade_raw, t, ‘linear’);
% Safety: Replace any remaining NaNs with 0
grade_interp(isnan(grade_interp)) = 0;
% Graphing
plot(t, grade_interp, ‘r-‘, ‘LineWidth’, 1.5);I am trying to use the interp1() function to first, plot a continuous graph between a variable and time. Then I want to use the plot to look up the value of the variable at every instant. However, my plot appears to have empty sections, which is probably why I get NaN errors in my calculations. I attached my excel file also.
grade_data = readmatrix(‘grade.xlsx’); % reads the excel file
t_grade_raw = grade_data(:, 1)’; % Extract Time (transpose to row vector)
grade_raw = grade_data(:, 2)’; % Extract Grade (transpose to row vector)
% Interpolating to plot
grade_interp = interp1(t_grade_raw, grade_raw, t, ‘linear’);
% Safety: Replace any remaining NaNs with 0
grade_interp(isnan(grade_interp)) = 0;
% Graphing
plot(t, grade_interp, ‘r-‘, ‘LineWidth’, 1.5); I am trying to use the interp1() function to first, plot a continuous graph between a variable and time. Then I want to use the plot to look up the value of the variable at every instant. However, my plot appears to have empty sections, which is probably why I get NaN errors in my calculations. I attached my excel file also.
grade_data = readmatrix(‘grade.xlsx’); % reads the excel file
t_grade_raw = grade_data(:, 1)’; % Extract Time (transpose to row vector)
grade_raw = grade_data(:, 2)’; % Extract Grade (transpose to row vector)
% Interpolating to plot
grade_interp = interp1(t_grade_raw, grade_raw, t, ‘linear’);
% Safety: Replace any remaining NaNs with 0
grade_interp(isnan(grade_interp)) = 0;
% Graphing
plot(t, grade_interp, ‘r-‘, ‘LineWidth’, 1.5); interpolation MATLAB Answers — New Questions
How to move a 3D volume in 6D (3 Translations and 3 Rotations)
Hello everyone,
I am simulating a CT volume that includes a couple of different structures using the "createSyntheticSkullCT" function. After that, I generate X-ray projections from the CT volume.
My goal is to move this CT volume in 6D, which includes translation in millimeters (X, Y, Z) and rotation in degrees (roll, pitch, yaw). To achieve this, I defined a function called "applyRigidTransform3D" in code 1 and "rigidTransform6D" in code 2 for the 6D movements, but I am not sure if this function is working correctly.
I would greatly appreciate any insights or suggestions regarding this code. Is my simulation realistic? If not, which parts contain errors? I would also welcome any recommended validation or sanity checks.
I have attached the MATLAB codes (Code1.m and Code2.m) below for reference.
Thank you!Hello everyone,
I am simulating a CT volume that includes a couple of different structures using the "createSyntheticSkullCT" function. After that, I generate X-ray projections from the CT volume.
My goal is to move this CT volume in 6D, which includes translation in millimeters (X, Y, Z) and rotation in degrees (roll, pitch, yaw). To achieve this, I defined a function called "applyRigidTransform3D" in code 1 and "rigidTransform6D" in code 2 for the 6D movements, but I am not sure if this function is working correctly.
I would greatly appreciate any insights or suggestions regarding this code. Is my simulation realistic? If not, which parts contain errors? I would also welcome any recommended validation or sanity checks.
I have attached the MATLAB codes (Code1.m and Code2.m) below for reference.
Thank you! Hello everyone,
I am simulating a CT volume that includes a couple of different structures using the "createSyntheticSkullCT" function. After that, I generate X-ray projections from the CT volume.
My goal is to move this CT volume in 6D, which includes translation in millimeters (X, Y, Z) and rotation in degrees (roll, pitch, yaw). To achieve this, I defined a function called "applyRigidTransform3D" in code 1 and "rigidTransform6D" in code 2 for the 6D movements, but I am not sure if this function is working correctly.
I would greatly appreciate any insights or suggestions regarding this code. Is my simulation realistic? If not, which parts contain errors? I would also welcome any recommended validation or sanity checks.
I have attached the MATLAB codes (Code1.m and Code2.m) below for reference.
Thank you! 3d volume, 6d movements, applyrigidtransform3d MATLAB Answers — New Questions
Trouble with Interp2
I am trying to use interp2 to look up values on in a table. I think that the problem is posed correctly (though obviously it is not), but all I get back is that the:
Error using interp2>makegriddedinterp (line 230)
Input grid is not a valid MESHGRID.
Error in interp2 (line 134)
F = makegriddedinterp(X, Y, V, method,extrap);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in LYNX_reflectivity_test_2 (line 61)
interp2(ang_mesh,ener_mesh,Refl,1,1000)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The code is below. The first step is to create a table of reflectivies as a function of angle and energy, interpolate that table line by line to create a finer grid in energy, and then test that the meshgrid works. That is where is fails, and I just can’t see what the problem is with the 2 interp2 statements at the bottom.
Thanks
Peter
Code below:
%Ir 10.nm/Cr 10.nm/SiO2 at 300.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 1000.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 5000.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 10000.eV, P=0.
%Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate
Ir_10nm_Cr_10nm= […
0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000
0.100000 0.982382 8.652573E-07 0.100000 0.980819 2.761637E-08 0.100000 0.961194 7.556862E-09 0.100000 0.970851 7.765713E-09
0.200000 0.965071 1.719669E-06 0.200000 0.961976 5.596694E-08 0.200000 0.922734 2.765021E-08 0.200000 0.938211 1.647113E-05
0.300000 0.948057 2.567899E-06 0.300000 0.943431 8.642812E-08 0.300000 0.883305 1.645055E-07 0.300000 0.892460 6.416535E-04
0.400000 0.931332 3.414433E-06 0.400000 0.925152 1.205377E-07 0.400000 0.841437 1.641682E-05 0.400000 0.776047 3.014587E-02
0.500000 0.914888 4.263738E-06 0.500000 0.907106 1.602024E-07 0.500000 0.795022 1.044327E-04 0.500000 0.414675 0.203665
0.600000 0.898715 5.120294E-06 0.600000 0.889262 2.079145E-07 0.600000 0.740373 6.502263E-04 0.600000 2.639916E-02 0.600880
0.700000 0.882807 5.988663E-06 0.700000 0.871589 2.670899E-07 0.700000 0.670460 4.532680E-03 0.700000 5.090132E-02 0.666863
0.800000 0.867156 6.873516E-06 0.800000 0.854059 3.426060E-07 0.800000 0.582072 1.752900E-02 0.800000 8.964668E-03 0.739812
0.900000 0.851754 7.779961E-06 0.900000 0.836637 4.418530E-07 0.900000 0.462636 3.669631E-02 0.900000 6.255109E-03 0.778701
1.00000 0.836595 8.712494E-06 1.00000 0.819307 5.757112E-07 1.00000 0.287212 8.603266E-02 1.00000 8.307789E-03 0.801262
1.10000 0.821673 9.676867E-06 1.10000 0.802032 7.623986E-07 1.10000 0.113086 0.191545 1.10000 3.204778E-03 0.823322
1.20000 0.806979 1.067877E-05 1.20000 0.784783 1.032557E-06 1.20000 4.265893E-02 0.302449 1.20000 1.369765E-03 0.841015
1.30000 0.792511 1.172367E-05 1.30000 0.767544 1.440837E-06 1.30000 3.424924E-02 0.377434 1.30000 2.013776E-03 0.853180
1.40000 0.778259 1.281891E-05 1.40000 0.750272 2.097700E-06 1.40000 4.541511E-02 0.422315 1.40000 2.044105E-03 0.863582
1.50000 0.764220 1.397090E-05 1.50000 0.732951 3.244685E-06 1.50000 3.447726E-02 0.462093 1.50000 8.998325E-05 0.874569
1.60000 0.750386 1.518820E-05 1.60000 0.715537 5.501835E-06 1.60000 1.121614E-02 0.507514 1.60000 8.285744E-04 0.881952
1.70000 0.736754 1.647850E-05 1.70000 0.698017 1.043718E-05 1.70000 3.812777E-03 0.545209 1.70000 9.592185E-04 0.888774
1.80000 0.723318 1.785118E-05 1.80000 0.680360 1.979164E-05 1.80000 5.419738E-03 0.572716 1.80000 1.404092E-04 0.895597
1.90000 0.710075 1.931691E-05 1.90000 0.662529 3.291488E-05 1.90000 6.503398E-03 0.595698 1.90000 3.395465E-04 0.901000
2.00000 0.697017 2.088734E-05 2.00000 0.644491 4.970375E-05 2.00000 8.737379E-03 0.614274 2.00000 3.610264E-04 0.905901
2.10000 0.684142 2.257595E-05 2.10000 0.626204 7.134984E-05 2.10000 8.188237E-03 0.631155 2.10000 3.175893E-04 0.910347
2.20000 0.671445 2.439662E-05 2.20000 0.607643 9.966306E-05 2.20000 3.437309E-03 0.649587 2.20000 3.847828E-05 0.914674
2.30000 0.658921 2.636680E-05 2.30000 0.588763 1.371713E-04 2.30000 5.906834E-04 0.666898 2.30000 2.018896E-04 0.918212
2.40000 0.646567 2.850380E-05 2.40000 0.569542 1.872420E-04 2.40000 1.199021E-03 0.680769 2.40000 2.279600E-04 0.921553
2.50000 0.634379 3.083119E-05 2.50000 0.549920 2.546647E-04 2.50000 1.850882E-03 0.692946 2.50000 2.762698E-05 0.924826
2.60000 0.622354 3.337174E-05 2.60000 0.529880 3.458717E-04 2.60000 2.201997E-03 0.704161 2.60000 1.045066E-04 0.927638
2.70000 0.610487 3.615420E-05 2.70000 0.509386 4.698597E-04 2.70000 2.767883E-03 0.714045 2.70000 1.058603E-04 0.930281
2.80000 0.598776 3.921089E-05 2.80000 0.488413 6.389660E-04 2.80000 2.139947E-03 0.723734 2.80000 9.618340E-05 0.932737
2.90000 0.587217 4.257846E-05 2.90000 0.466955 8.699156E-04 2.90000 6.292278E-04 0.733747 2.90000 1.226485E-05 0.935114
3.00000 0.575808 4.630103E-05 3.00000 0.445010 1.185337E-03 3.00000 1.415811E-04 0.742847 3.00000 7.197971E-05 0.937195];
angle = [0:.1:3];
energy = [300:970:10000];
[ener_mesh, ang_mesh] = meshgrid(energy,angle);
i = 1;
indexs = [2 5 8 11];
energy_start = [300 1000 5000 10000];
Refl = zeros(length(angle),length(energy));
row_i = zeros(1,length(energy));
%Refl(i,:) = ones(1,length(energy));
for i = 1:1:length(angle)
row_i = row_i*0;
row_i = interp1(energy_start,Ir_10nm_Cr_10nm(i,indexs),energy,"linear");
Refl(i,:) = row_i;
end %end of for
%test above
ang_mesh
ener_mesh
Refl
interp2(ang_mesh,ener_mesh,Refl,1,1000)
interp2(ang_mesh,ener_mesh,Refl,2.6,10000)I am trying to use interp2 to look up values on in a table. I think that the problem is posed correctly (though obviously it is not), but all I get back is that the:
Error using interp2>makegriddedinterp (line 230)
Input grid is not a valid MESHGRID.
Error in interp2 (line 134)
F = makegriddedinterp(X, Y, V, method,extrap);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in LYNX_reflectivity_test_2 (line 61)
interp2(ang_mesh,ener_mesh,Refl,1,1000)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The code is below. The first step is to create a table of reflectivies as a function of angle and energy, interpolate that table line by line to create a finer grid in energy, and then test that the meshgrid works. That is where is fails, and I just can’t see what the problem is with the 2 interp2 statements at the bottom.
Thanks
Peter
Code below:
%Ir 10.nm/Cr 10.nm/SiO2 at 300.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 1000.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 5000.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 10000.eV, P=0.
%Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate
Ir_10nm_Cr_10nm= […
0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000
0.100000 0.982382 8.652573E-07 0.100000 0.980819 2.761637E-08 0.100000 0.961194 7.556862E-09 0.100000 0.970851 7.765713E-09
0.200000 0.965071 1.719669E-06 0.200000 0.961976 5.596694E-08 0.200000 0.922734 2.765021E-08 0.200000 0.938211 1.647113E-05
0.300000 0.948057 2.567899E-06 0.300000 0.943431 8.642812E-08 0.300000 0.883305 1.645055E-07 0.300000 0.892460 6.416535E-04
0.400000 0.931332 3.414433E-06 0.400000 0.925152 1.205377E-07 0.400000 0.841437 1.641682E-05 0.400000 0.776047 3.014587E-02
0.500000 0.914888 4.263738E-06 0.500000 0.907106 1.602024E-07 0.500000 0.795022 1.044327E-04 0.500000 0.414675 0.203665
0.600000 0.898715 5.120294E-06 0.600000 0.889262 2.079145E-07 0.600000 0.740373 6.502263E-04 0.600000 2.639916E-02 0.600880
0.700000 0.882807 5.988663E-06 0.700000 0.871589 2.670899E-07 0.700000 0.670460 4.532680E-03 0.700000 5.090132E-02 0.666863
0.800000 0.867156 6.873516E-06 0.800000 0.854059 3.426060E-07 0.800000 0.582072 1.752900E-02 0.800000 8.964668E-03 0.739812
0.900000 0.851754 7.779961E-06 0.900000 0.836637 4.418530E-07 0.900000 0.462636 3.669631E-02 0.900000 6.255109E-03 0.778701
1.00000 0.836595 8.712494E-06 1.00000 0.819307 5.757112E-07 1.00000 0.287212 8.603266E-02 1.00000 8.307789E-03 0.801262
1.10000 0.821673 9.676867E-06 1.10000 0.802032 7.623986E-07 1.10000 0.113086 0.191545 1.10000 3.204778E-03 0.823322
1.20000 0.806979 1.067877E-05 1.20000 0.784783 1.032557E-06 1.20000 4.265893E-02 0.302449 1.20000 1.369765E-03 0.841015
1.30000 0.792511 1.172367E-05 1.30000 0.767544 1.440837E-06 1.30000 3.424924E-02 0.377434 1.30000 2.013776E-03 0.853180
1.40000 0.778259 1.281891E-05 1.40000 0.750272 2.097700E-06 1.40000 4.541511E-02 0.422315 1.40000 2.044105E-03 0.863582
1.50000 0.764220 1.397090E-05 1.50000 0.732951 3.244685E-06 1.50000 3.447726E-02 0.462093 1.50000 8.998325E-05 0.874569
1.60000 0.750386 1.518820E-05 1.60000 0.715537 5.501835E-06 1.60000 1.121614E-02 0.507514 1.60000 8.285744E-04 0.881952
1.70000 0.736754 1.647850E-05 1.70000 0.698017 1.043718E-05 1.70000 3.812777E-03 0.545209 1.70000 9.592185E-04 0.888774
1.80000 0.723318 1.785118E-05 1.80000 0.680360 1.979164E-05 1.80000 5.419738E-03 0.572716 1.80000 1.404092E-04 0.895597
1.90000 0.710075 1.931691E-05 1.90000 0.662529 3.291488E-05 1.90000 6.503398E-03 0.595698 1.90000 3.395465E-04 0.901000
2.00000 0.697017 2.088734E-05 2.00000 0.644491 4.970375E-05 2.00000 8.737379E-03 0.614274 2.00000 3.610264E-04 0.905901
2.10000 0.684142 2.257595E-05 2.10000 0.626204 7.134984E-05 2.10000 8.188237E-03 0.631155 2.10000 3.175893E-04 0.910347
2.20000 0.671445 2.439662E-05 2.20000 0.607643 9.966306E-05 2.20000 3.437309E-03 0.649587 2.20000 3.847828E-05 0.914674
2.30000 0.658921 2.636680E-05 2.30000 0.588763 1.371713E-04 2.30000 5.906834E-04 0.666898 2.30000 2.018896E-04 0.918212
2.40000 0.646567 2.850380E-05 2.40000 0.569542 1.872420E-04 2.40000 1.199021E-03 0.680769 2.40000 2.279600E-04 0.921553
2.50000 0.634379 3.083119E-05 2.50000 0.549920 2.546647E-04 2.50000 1.850882E-03 0.692946 2.50000 2.762698E-05 0.924826
2.60000 0.622354 3.337174E-05 2.60000 0.529880 3.458717E-04 2.60000 2.201997E-03 0.704161 2.60000 1.045066E-04 0.927638
2.70000 0.610487 3.615420E-05 2.70000 0.509386 4.698597E-04 2.70000 2.767883E-03 0.714045 2.70000 1.058603E-04 0.930281
2.80000 0.598776 3.921089E-05 2.80000 0.488413 6.389660E-04 2.80000 2.139947E-03 0.723734 2.80000 9.618340E-05 0.932737
2.90000 0.587217 4.257846E-05 2.90000 0.466955 8.699156E-04 2.90000 6.292278E-04 0.733747 2.90000 1.226485E-05 0.935114
3.00000 0.575808 4.630103E-05 3.00000 0.445010 1.185337E-03 3.00000 1.415811E-04 0.742847 3.00000 7.197971E-05 0.937195];
angle = [0:.1:3];
energy = [300:970:10000];
[ener_mesh, ang_mesh] = meshgrid(energy,angle);
i = 1;
indexs = [2 5 8 11];
energy_start = [300 1000 5000 10000];
Refl = zeros(length(angle),length(energy));
row_i = zeros(1,length(energy));
%Refl(i,:) = ones(1,length(energy));
for i = 1:1:length(angle)
row_i = row_i*0;
row_i = interp1(energy_start,Ir_10nm_Cr_10nm(i,indexs),energy,"linear");
Refl(i,:) = row_i;
end %end of for
%test above
ang_mesh
ener_mesh
Refl
interp2(ang_mesh,ener_mesh,Refl,1,1000)
interp2(ang_mesh,ener_mesh,Refl,2.6,10000) I am trying to use interp2 to look up values on in a table. I think that the problem is posed correctly (though obviously it is not), but all I get back is that the:
Error using interp2>makegriddedinterp (line 230)
Input grid is not a valid MESHGRID.
Error in interp2 (line 134)
F = makegriddedinterp(X, Y, V, method,extrap);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in LYNX_reflectivity_test_2 (line 61)
interp2(ang_mesh,ener_mesh,Refl,1,1000)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The code is below. The first step is to create a table of reflectivies as a function of angle and energy, interpolate that table line by line to create a finer grid in energy, and then test that the meshgrid works. That is where is fails, and I just can’t see what the problem is with the 2 interp2 statements at the bottom.
Thanks
Peter
Code below:
%Ir 10.nm/Cr 10.nm/SiO2 at 300.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 1000.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 5000.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 10000.eV, P=0.
%Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate
Ir_10nm_Cr_10nm= […
0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000
0.100000 0.982382 8.652573E-07 0.100000 0.980819 2.761637E-08 0.100000 0.961194 7.556862E-09 0.100000 0.970851 7.765713E-09
0.200000 0.965071 1.719669E-06 0.200000 0.961976 5.596694E-08 0.200000 0.922734 2.765021E-08 0.200000 0.938211 1.647113E-05
0.300000 0.948057 2.567899E-06 0.300000 0.943431 8.642812E-08 0.300000 0.883305 1.645055E-07 0.300000 0.892460 6.416535E-04
0.400000 0.931332 3.414433E-06 0.400000 0.925152 1.205377E-07 0.400000 0.841437 1.641682E-05 0.400000 0.776047 3.014587E-02
0.500000 0.914888 4.263738E-06 0.500000 0.907106 1.602024E-07 0.500000 0.795022 1.044327E-04 0.500000 0.414675 0.203665
0.600000 0.898715 5.120294E-06 0.600000 0.889262 2.079145E-07 0.600000 0.740373 6.502263E-04 0.600000 2.639916E-02 0.600880
0.700000 0.882807 5.988663E-06 0.700000 0.871589 2.670899E-07 0.700000 0.670460 4.532680E-03 0.700000 5.090132E-02 0.666863
0.800000 0.867156 6.873516E-06 0.800000 0.854059 3.426060E-07 0.800000 0.582072 1.752900E-02 0.800000 8.964668E-03 0.739812
0.900000 0.851754 7.779961E-06 0.900000 0.836637 4.418530E-07 0.900000 0.462636 3.669631E-02 0.900000 6.255109E-03 0.778701
1.00000 0.836595 8.712494E-06 1.00000 0.819307 5.757112E-07 1.00000 0.287212 8.603266E-02 1.00000 8.307789E-03 0.801262
1.10000 0.821673 9.676867E-06 1.10000 0.802032 7.623986E-07 1.10000 0.113086 0.191545 1.10000 3.204778E-03 0.823322
1.20000 0.806979 1.067877E-05 1.20000 0.784783 1.032557E-06 1.20000 4.265893E-02 0.302449 1.20000 1.369765E-03 0.841015
1.30000 0.792511 1.172367E-05 1.30000 0.767544 1.440837E-06 1.30000 3.424924E-02 0.377434 1.30000 2.013776E-03 0.853180
1.40000 0.778259 1.281891E-05 1.40000 0.750272 2.097700E-06 1.40000 4.541511E-02 0.422315 1.40000 2.044105E-03 0.863582
1.50000 0.764220 1.397090E-05 1.50000 0.732951 3.244685E-06 1.50000 3.447726E-02 0.462093 1.50000 8.998325E-05 0.874569
1.60000 0.750386 1.518820E-05 1.60000 0.715537 5.501835E-06 1.60000 1.121614E-02 0.507514 1.60000 8.285744E-04 0.881952
1.70000 0.736754 1.647850E-05 1.70000 0.698017 1.043718E-05 1.70000 3.812777E-03 0.545209 1.70000 9.592185E-04 0.888774
1.80000 0.723318 1.785118E-05 1.80000 0.680360 1.979164E-05 1.80000 5.419738E-03 0.572716 1.80000 1.404092E-04 0.895597
1.90000 0.710075 1.931691E-05 1.90000 0.662529 3.291488E-05 1.90000 6.503398E-03 0.595698 1.90000 3.395465E-04 0.901000
2.00000 0.697017 2.088734E-05 2.00000 0.644491 4.970375E-05 2.00000 8.737379E-03 0.614274 2.00000 3.610264E-04 0.905901
2.10000 0.684142 2.257595E-05 2.10000 0.626204 7.134984E-05 2.10000 8.188237E-03 0.631155 2.10000 3.175893E-04 0.910347
2.20000 0.671445 2.439662E-05 2.20000 0.607643 9.966306E-05 2.20000 3.437309E-03 0.649587 2.20000 3.847828E-05 0.914674
2.30000 0.658921 2.636680E-05 2.30000 0.588763 1.371713E-04 2.30000 5.906834E-04 0.666898 2.30000 2.018896E-04 0.918212
2.40000 0.646567 2.850380E-05 2.40000 0.569542 1.872420E-04 2.40000 1.199021E-03 0.680769 2.40000 2.279600E-04 0.921553
2.50000 0.634379 3.083119E-05 2.50000 0.549920 2.546647E-04 2.50000 1.850882E-03 0.692946 2.50000 2.762698E-05 0.924826
2.60000 0.622354 3.337174E-05 2.60000 0.529880 3.458717E-04 2.60000 2.201997E-03 0.704161 2.60000 1.045066E-04 0.927638
2.70000 0.610487 3.615420E-05 2.70000 0.509386 4.698597E-04 2.70000 2.767883E-03 0.714045 2.70000 1.058603E-04 0.930281
2.80000 0.598776 3.921089E-05 2.80000 0.488413 6.389660E-04 2.80000 2.139947E-03 0.723734 2.80000 9.618340E-05 0.932737
2.90000 0.587217 4.257846E-05 2.90000 0.466955 8.699156E-04 2.90000 6.292278E-04 0.733747 2.90000 1.226485E-05 0.935114
3.00000 0.575808 4.630103E-05 3.00000 0.445010 1.185337E-03 3.00000 1.415811E-04 0.742847 3.00000 7.197971E-05 0.937195];
angle = [0:.1:3];
energy = [300:970:10000];
[ener_mesh, ang_mesh] = meshgrid(energy,angle);
i = 1;
indexs = [2 5 8 11];
energy_start = [300 1000 5000 10000];
Refl = zeros(length(angle),length(energy));
row_i = zeros(1,length(energy));
%Refl(i,:) = ones(1,length(energy));
for i = 1:1:length(angle)
row_i = row_i*0;
row_i = interp1(energy_start,Ir_10nm_Cr_10nm(i,indexs),energy,"linear");
Refl(i,:) = row_i;
end %end of for
%test above
ang_mesh
ener_mesh
Refl
interp2(ang_mesh,ener_mesh,Refl,1,1000)
interp2(ang_mesh,ener_mesh,Refl,2.6,10000) interp2 question MATLAB Answers — New Questions
Automated Driving Toolbox 3D simulation on Macbook Air M4
Hey guys!
I just purchased a Macbook Air M4 because i needed it for my dissertation and it turns out it won’t run Unreal Engine powered 3D simulations. I’m working on Automated Driving Toolbox in Simulink and I run radar and camera powered assist systems like Front Assist, Lane Assist and Adaptive Cruise Control, and now I need to start working on V2X comms. I’m now on the fence because I feel like I have to return my Macbook even though i clearly dont want to because i love it but I have no choice if i cant do my work on it.
Do you guys now of any solutions? Matlab Online won’t work due to the sheer size of my project and it just takes forever to run.
Thank you!Hey guys!
I just purchased a Macbook Air M4 because i needed it for my dissertation and it turns out it won’t run Unreal Engine powered 3D simulations. I’m working on Automated Driving Toolbox in Simulink and I run radar and camera powered assist systems like Front Assist, Lane Assist and Adaptive Cruise Control, and now I need to start working on V2X comms. I’m now on the fence because I feel like I have to return my Macbook even though i clearly dont want to because i love it but I have no choice if i cant do my work on it.
Do you guys now of any solutions? Matlab Online won’t work due to the sheer size of my project and it just takes forever to run.
Thank you! Hey guys!
I just purchased a Macbook Air M4 because i needed it for my dissertation and it turns out it won’t run Unreal Engine powered 3D simulations. I’m working on Automated Driving Toolbox in Simulink and I run radar and camera powered assist systems like Front Assist, Lane Assist and Adaptive Cruise Control, and now I need to start working on V2X comms. I’m now on the fence because I feel like I have to return my Macbook even though i clearly dont want to because i love it but I have no choice if i cant do my work on it.
Do you guys now of any solutions? Matlab Online won’t work due to the sheer size of my project and it just takes forever to run.
Thank you! 3d, simulation, macbook, unreal, engine, matlab, simulink, automated, driving, toolbox MATLAB Answers — New Questions
AMD vs Intel and Single-Core vs Multi-core CPU Performance Selection for Simulink Speed
I’m a grad student who frequently does power electronics simulations in Simulink. I am thinking of getting a new PC with 32 GB RAM (5600 MHz) and need to select the CPU. I’ve stumbled upon supposedly good options, such as the Intel i9-14900K (or i7-14700F if I go for significantly cheaper), and the AMD Ryzen 7 9800X3D. Which will be faster for Simulink simulations? Does the fact that the i9 has 24 cores vs the Ryzen 7’s 8 cores make a big difference, or is Simulink, by default, bottlenecked by single-core performance?
I read that the Ryzen 7 9800X3D has higher single-core performance, but the i9-14900K will have better multicore performance and is favourable if I ran multiple simulations at once or used parallel computing. However, the parallel computing toolbox seems difficult to use, so I don’t know if I’d like to amend all of my simulation practices to adhere to it.
Please don’t suggest making my simulations different or optimized; I understand that that will make a great difference in simulation speed. Also, I’m sorry if my lack of computer hardware knowledge is showing!I’m a grad student who frequently does power electronics simulations in Simulink. I am thinking of getting a new PC with 32 GB RAM (5600 MHz) and need to select the CPU. I’ve stumbled upon supposedly good options, such as the Intel i9-14900K (or i7-14700F if I go for significantly cheaper), and the AMD Ryzen 7 9800X3D. Which will be faster for Simulink simulations? Does the fact that the i9 has 24 cores vs the Ryzen 7’s 8 cores make a big difference, or is Simulink, by default, bottlenecked by single-core performance?
I read that the Ryzen 7 9800X3D has higher single-core performance, but the i9-14900K will have better multicore performance and is favourable if I ran multiple simulations at once or used parallel computing. However, the parallel computing toolbox seems difficult to use, so I don’t know if I’d like to amend all of my simulation practices to adhere to it.
Please don’t suggest making my simulations different or optimized; I understand that that will make a great difference in simulation speed. Also, I’m sorry if my lack of computer hardware knowledge is showing! I’m a grad student who frequently does power electronics simulations in Simulink. I am thinking of getting a new PC with 32 GB RAM (5600 MHz) and need to select the CPU. I’ve stumbled upon supposedly good options, such as the Intel i9-14900K (or i7-14700F if I go for significantly cheaper), and the AMD Ryzen 7 9800X3D. Which will be faster for Simulink simulations? Does the fact that the i9 has 24 cores vs the Ryzen 7’s 8 cores make a big difference, or is Simulink, by default, bottlenecked by single-core performance?
I read that the Ryzen 7 9800X3D has higher single-core performance, but the i9-14900K will have better multicore performance and is favourable if I ran multiple simulations at once or used parallel computing. However, the parallel computing toolbox seems difficult to use, so I don’t know if I’d like to amend all of my simulation practices to adhere to it.
Please don’t suggest making my simulations different or optimized; I understand that that will make a great difference in simulation speed. Also, I’m sorry if my lack of computer hardware knowledge is showing! simulink, speed MATLAB Answers — New Questions









