Category: Matlab
Category Archives: Matlab
how can I convert linear figure’s axis to logarithmic?
Hi,
I have following Figure#1, I want to convert only y-axis to logaritmic scale. I tried several ways but each time outcome is not normal. Can you please tell me how to achive y-axis of Figure#2. Thanks for you help.
% this my figure script.
figure;
imagesc(t, fliplr(f), ST_normalized)
previously I used the follwing command, it did not work. I want to have the image of Figure#2 in y-axis.
for instance, "10" in Figure#1 shoud be "10^1" in a new scaled figure.
set(gca, ‘YScale’, ‘log’)Hi,
I have following Figure#1, I want to convert only y-axis to logaritmic scale. I tried several ways but each time outcome is not normal. Can you please tell me how to achive y-axis of Figure#2. Thanks for you help.
% this my figure script.
figure;
imagesc(t, fliplr(f), ST_normalized)
previously I used the follwing command, it did not work. I want to have the image of Figure#2 in y-axis.
for instance, "10" in Figure#1 shoud be "10^1" in a new scaled figure.
set(gca, ‘YScale’, ‘log’) Hi,
I have following Figure#1, I want to convert only y-axis to logaritmic scale. I tried several ways but each time outcome is not normal. Can you please tell me how to achive y-axis of Figure#2. Thanks for you help.
% this my figure script.
figure;
imagesc(t, fliplr(f), ST_normalized)
previously I used the follwing command, it did not work. I want to have the image of Figure#2 in y-axis.
for instance, "10" in Figure#1 shoud be "10^1" in a new scaled figure.
set(gca, ‘YScale’, ‘log’) matlab, figure, scale MATLAB Answers — New Questions
Massive slowdown for Apple Silicon in computing SVD
I recently notice that there is an extreme slowdown in my version of Matlab while computing an SVD when the size of the matrix crosses some threshold. I came up with the following example that demonstrates my issue:
N = [10000 11000 12000 13000];
for i = 1:4
A = randn(N(i),3);
tic;
[U,S,V] = svd(A,0);
toc;
end
When I run this in Matlab R2024b (macOS Apple silicon), the output is:
Elapsed time is 0.000396 seconds.
Elapsed time is 0.000275 seconds.
Elapsed time is 0.000264 seconds.
Elapsed time is 0.083150 seconds.
Of course the exact numbers vary trial to trial, but the speed for the last run (where N = 13000) is consistently orders of magnitude slower.
When I run this same code on Matlab R2024b (Intel processor) on the same computer, this slow down does not happen. I was able to replicate this issue across two different Macs (one with M1 and another with M3) and different versions of Matlab (going back to R2023b).
Any idea why this might be happening in the silicon version?
Edit: I’m running macOS 15.1.1I recently notice that there is an extreme slowdown in my version of Matlab while computing an SVD when the size of the matrix crosses some threshold. I came up with the following example that demonstrates my issue:
N = [10000 11000 12000 13000];
for i = 1:4
A = randn(N(i),3);
tic;
[U,S,V] = svd(A,0);
toc;
end
When I run this in Matlab R2024b (macOS Apple silicon), the output is:
Elapsed time is 0.000396 seconds.
Elapsed time is 0.000275 seconds.
Elapsed time is 0.000264 seconds.
Elapsed time is 0.083150 seconds.
Of course the exact numbers vary trial to trial, but the speed for the last run (where N = 13000) is consistently orders of magnitude slower.
When I run this same code on Matlab R2024b (Intel processor) on the same computer, this slow down does not happen. I was able to replicate this issue across two different Macs (one with M1 and another with M3) and different versions of Matlab (going back to R2023b).
Any idea why this might be happening in the silicon version?
Edit: I’m running macOS 15.1.1 I recently notice that there is an extreme slowdown in my version of Matlab while computing an SVD when the size of the matrix crosses some threshold. I came up with the following example that demonstrates my issue:
N = [10000 11000 12000 13000];
for i = 1:4
A = randn(N(i),3);
tic;
[U,S,V] = svd(A,0);
toc;
end
When I run this in Matlab R2024b (macOS Apple silicon), the output is:
Elapsed time is 0.000396 seconds.
Elapsed time is 0.000275 seconds.
Elapsed time is 0.000264 seconds.
Elapsed time is 0.083150 seconds.
Of course the exact numbers vary trial to trial, but the speed for the last run (where N = 13000) is consistently orders of magnitude slower.
When I run this same code on Matlab R2024b (Intel processor) on the same computer, this slow down does not happen. I was able to replicate this issue across two different Macs (one with M1 and another with M3) and different versions of Matlab (going back to R2023b).
Any idea why this might be happening in the silicon version?
Edit: I’m running macOS 15.1.1 svd, mac, memory, speed MATLAB Answers — New Questions
Error using save, too many output arguments – don’t know how to fix.
Hi y’all
I am trying to save multiple tables I’ve edited in matlab, but I get this error:
Error using save
Too many output arguments.
I’m having trouble figuring out how to fix this. The code it’s probably referring to is:
function [output] = save_on_Computer(ReferenceData, month, day)
file_name = "OL_"+month+"_"+day+".csv" ;
savefile = save(file_name) ;
output = savefile ;
end
from the full code here:
% Pull data from files
function [output] = each_day_table(month, day)
fileNames = sprintf(‘D2024%02d%02d*.csv’, month, day) ;
datastore_result = datastore(fileNames) ;
original_data = readall(datastore_result) ;
output = original_data ;
end
% Find Where Equivilant Diamiter > 150 And Remove (ICB measures b/w 2 – 150 μm)
function [output] = remove_150(original)
new = original ;
Greater150 = original.EquivDiameter > 150 ;
new(Greater150, 🙂 = [] ;
output = new ;
end
% To Save Each Newly Made File Onto Computer
function [output] = save_on_Computer(ReferenceData, month, day)
file_name = "OL_"+month+"_"+day+".csv" ;
savefile = save(file_name) ;
output = savefile ;
end
function [output] = do_everything(year, month, day)
original_data = each_day_table(month, day) ;
data_lessthan_150 = remove_150( original_data) ;
save_to_folder = save_on_Computer(data_without_zeroes, month, day) ;
output = save_on_Computer ; % change data_with_surface_area with data_with_ratio
end
OL_06_03 = do_everything (2024,06,03) ;
OL_06_04 = do_everything (2024,06,04) ;
OL_06_05 = do_everything (2024,06,05) ;
OL_06_06 = do_everything (2024,06,06) ;Hi y’all
I am trying to save multiple tables I’ve edited in matlab, but I get this error:
Error using save
Too many output arguments.
I’m having trouble figuring out how to fix this. The code it’s probably referring to is:
function [output] = save_on_Computer(ReferenceData, month, day)
file_name = "OL_"+month+"_"+day+".csv" ;
savefile = save(file_name) ;
output = savefile ;
end
from the full code here:
% Pull data from files
function [output] = each_day_table(month, day)
fileNames = sprintf(‘D2024%02d%02d*.csv’, month, day) ;
datastore_result = datastore(fileNames) ;
original_data = readall(datastore_result) ;
output = original_data ;
end
% Find Where Equivilant Diamiter > 150 And Remove (ICB measures b/w 2 – 150 μm)
function [output] = remove_150(original)
new = original ;
Greater150 = original.EquivDiameter > 150 ;
new(Greater150, 🙂 = [] ;
output = new ;
end
% To Save Each Newly Made File Onto Computer
function [output] = save_on_Computer(ReferenceData, month, day)
file_name = "OL_"+month+"_"+day+".csv" ;
savefile = save(file_name) ;
output = savefile ;
end
function [output] = do_everything(year, month, day)
original_data = each_day_table(month, day) ;
data_lessthan_150 = remove_150( original_data) ;
save_to_folder = save_on_Computer(data_without_zeroes, month, day) ;
output = save_on_Computer ; % change data_with_surface_area with data_with_ratio
end
OL_06_03 = do_everything (2024,06,03) ;
OL_06_04 = do_everything (2024,06,04) ;
OL_06_05 = do_everything (2024,06,05) ;
OL_06_06 = do_everything (2024,06,06) ; Hi y’all
I am trying to save multiple tables I’ve edited in matlab, but I get this error:
Error using save
Too many output arguments.
I’m having trouble figuring out how to fix this. The code it’s probably referring to is:
function [output] = save_on_Computer(ReferenceData, month, day)
file_name = "OL_"+month+"_"+day+".csv" ;
savefile = save(file_name) ;
output = savefile ;
end
from the full code here:
% Pull data from files
function [output] = each_day_table(month, day)
fileNames = sprintf(‘D2024%02d%02d*.csv’, month, day) ;
datastore_result = datastore(fileNames) ;
original_data = readall(datastore_result) ;
output = original_data ;
end
% Find Where Equivilant Diamiter > 150 And Remove (ICB measures b/w 2 – 150 μm)
function [output] = remove_150(original)
new = original ;
Greater150 = original.EquivDiameter > 150 ;
new(Greater150, 🙂 = [] ;
output = new ;
end
% To Save Each Newly Made File Onto Computer
function [output] = save_on_Computer(ReferenceData, month, day)
file_name = "OL_"+month+"_"+day+".csv" ;
savefile = save(file_name) ;
output = savefile ;
end
function [output] = do_everything(year, month, day)
original_data = each_day_table(month, day) ;
data_lessthan_150 = remove_150( original_data) ;
save_to_folder = save_on_Computer(data_without_zeroes, month, day) ;
output = save_on_Computer ; % change data_with_surface_area with data_with_ratio
end
OL_06_03 = do_everything (2024,06,03) ;
OL_06_04 = do_everything (2024,06,04) ;
OL_06_05 = do_everything (2024,06,05) ;
OL_06_06 = do_everything (2024,06,06) ; save, error MATLAB Answers — New Questions
how to find the accuracy from the predicted labels for test data in Matlab?
I am using classification learner app svm generated code for the classification of multiclass dataset.
Now I wanted to test with the unseen dataset for this I am using yfit.
Now I got the predicted labels for the test data. How to find the test accuracy and from the predicted laebls?
Can someone please help me in this.I am using classification learner app svm generated code for the classification of multiclass dataset.
Now I wanted to test with the unseen dataset for this I am using yfit.
Now I got the predicted labels for the test data. How to find the test accuracy and from the predicted laebls?
Can someone please help me in this. I am using classification learner app svm generated code for the classification of multiclass dataset.
Now I wanted to test with the unseen dataset for this I am using yfit.
Now I got the predicted labels for the test data. How to find the test accuracy and from the predicted laebls?
Can someone please help me in this. calculate test data accuracy MATLAB Answers — New Questions
C-Caller Block in Rapid Accelerator Mode with Busses
Is it possible to use the C-Caller in rapid accelerator mode when using buses?
When I include my structs as buses using `Simulink.importExternalCTypes`, I can’t run my simulation in rapid accelerator mode, because there is a name collision between my c code and the code generated by the rapid accelerator build process.
Renaming the structs in my code does not work, as then my c -caller blocks don’t recognize them as valid input/output dataformats.
This problem can be reproduced by using the C-Caller example "Call C Functions Using C Caller Block" (https://de.mathworks.com/help/releases/R2024b/simulink/slref/call-c-functions-using-c-caller-block.html).
When switching the example to rapid accelerator mode, the same problem occurs.Is it possible to use the C-Caller in rapid accelerator mode when using buses?
When I include my structs as buses using `Simulink.importExternalCTypes`, I can’t run my simulation in rapid accelerator mode, because there is a name collision between my c code and the code generated by the rapid accelerator build process.
Renaming the structs in my code does not work, as then my c -caller blocks don’t recognize them as valid input/output dataformats.
This problem can be reproduced by using the C-Caller example "Call C Functions Using C Caller Block" (https://de.mathworks.com/help/releases/R2024b/simulink/slref/call-c-functions-using-c-caller-block.html).
When switching the example to rapid accelerator mode, the same problem occurs. Is it possible to use the C-Caller in rapid accelerator mode when using buses?
When I include my structs as buses using `Simulink.importExternalCTypes`, I can’t run my simulation in rapid accelerator mode, because there is a name collision between my c code and the code generated by the rapid accelerator build process.
Renaming the structs in my code does not work, as then my c -caller blocks don’t recognize them as valid input/output dataformats.
This problem can be reproduced by using the C-Caller example "Call C Functions Using C Caller Block" (https://de.mathworks.com/help/releases/R2024b/simulink/slref/call-c-functions-using-c-caller-block.html).
When switching the example to rapid accelerator mode, the same problem occurs. c-code, c-caller, code-integration, rapid-accelerator, simulink, simulation MATLAB Answers — New Questions
Why this error is occuring while deploying in ROS2?
Hey all, I am trying to deploy in a ROS2 device from Simulink. I keep facing this error. FYI, the device being deployed in is Intel Nuc. It is being deployed through Wi-Fi. I also deployed in another ROS2 machine without any error therefore the Simulink model has no error by design. Please don’t hesitate to ask for further information. Glad to provide to solve the issue.Hey all, I am trying to deploy in a ROS2 device from Simulink. I keep facing this error. FYI, the device being deployed in is Intel Nuc. It is being deployed through Wi-Fi. I also deployed in another ROS2 machine without any error therefore the Simulink model has no error by design. Please don’t hesitate to ask for further information. Glad to provide to solve the issue. Hey all, I am trying to deploy in a ROS2 device from Simulink. I keep facing this error. FYI, the device being deployed in is Intel Nuc. It is being deployed through Wi-Fi. I also deployed in another ROS2 machine without any error therefore the Simulink model has no error by design. Please don’t hesitate to ask for further information. Glad to provide to solve the issue. ros2, simulink MATLAB Answers — New Questions
When I import a Creo model to Simscape Multibody, some of my reference frames are not being imported. Is there something I need to do in Creo or in Simscape?
I have imported a Creo model via the multibody link to Simscape. When I open the model in Mechanics Explorer, the model itself has been imported correctly, but not all the reference frames are imported (I set reference frames at the desired locations in Creo). I want my reference point at a specific location on my model so that I can measure the position (x, y, z). How can I ensure that all reference frames are imported correctly and set a reference point at a specific location?I have imported a Creo model via the multibody link to Simscape. When I open the model in Mechanics Explorer, the model itself has been imported correctly, but not all the reference frames are imported (I set reference frames at the desired locations in Creo). I want my reference point at a specific location on my model so that I can measure the position (x, y, z). How can I ensure that all reference frames are imported correctly and set a reference point at a specific location? I have imported a Creo model via the multibody link to Simscape. When I open the model in Mechanics Explorer, the model itself has been imported correctly, but not all the reference frames are imported (I set reference frames at the desired locations in Creo). I want my reference point at a specific location on my model so that I can measure the position (x, y, z). How can I ensure that all reference frames are imported correctly and set a reference point at a specific location? multibody link MATLAB Answers — New Questions
How to perform definite integration with non-commutable symbolic coefficients?
Hi All,
I am trying to perform a definite integration in X (length axis) to calculate some beam modeshapes, following this the variables will be passed into a time integration using ode45. In the integration there are beam modeshape terms (W) which are a function of x and there are time dependent terms (qw) which are not. Crucially the qw terms are not commutable so cannot be factored out of the integrals. I need the answer to W6 to be given in terms W6=Y1*qw1+Y2*qw2… where Y1 and Y2 are numerical coefficients.
Here is my code:
clear all
clc
syms x qw1 qw2
L=0.52;
qw=[qw1; qw2];
%Bending Mode
Landa=[1.875104069 4.694091133];% 7.854757];% 10.99554];
for j=1:length(Landa)
SIGMA(j)=(cos(Landa(j))+cosh(Landa(j)))/(sin(Landa(j))+sinh(Landa(j)));
W(j)=cosh(Landa(j)*x/L)-cos(Landa(j)*x/L)-SIGMA(j)*(sinh(Landa(j)*x/L)-sin(Landa(j)*x/L));
end
% Integration in X over length of beam
W6=(vpaintegral(W*diff(diff(W,x,1)*qw*diff(diff(W,x,1)*qw*diff(W,x,2)*qw,x,1),x,1),0,L));
The value W6 is left as symbolic without the integrals being solved, this means that when I pass the W6 term into the time integration in a separate script and solve for qw terms the time integration is much slower because it is computing the spatial integration in X for each time of the 1000 time-steps.
I have tried using the ‘double’,’simplify’ and ‘collect’ commands but I have not been able to get the result in the form I want it. So what I’m asking is, is there a way to "force" matlab to do the integrations with the symbolic coefficients attahced. Any help would be much appreciated!Hi All,
I am trying to perform a definite integration in X (length axis) to calculate some beam modeshapes, following this the variables will be passed into a time integration using ode45. In the integration there are beam modeshape terms (W) which are a function of x and there are time dependent terms (qw) which are not. Crucially the qw terms are not commutable so cannot be factored out of the integrals. I need the answer to W6 to be given in terms W6=Y1*qw1+Y2*qw2… where Y1 and Y2 are numerical coefficients.
Here is my code:
clear all
clc
syms x qw1 qw2
L=0.52;
qw=[qw1; qw2];
%Bending Mode
Landa=[1.875104069 4.694091133];% 7.854757];% 10.99554];
for j=1:length(Landa)
SIGMA(j)=(cos(Landa(j))+cosh(Landa(j)))/(sin(Landa(j))+sinh(Landa(j)));
W(j)=cosh(Landa(j)*x/L)-cos(Landa(j)*x/L)-SIGMA(j)*(sinh(Landa(j)*x/L)-sin(Landa(j)*x/L));
end
% Integration in X over length of beam
W6=(vpaintegral(W*diff(diff(W,x,1)*qw*diff(diff(W,x,1)*qw*diff(W,x,2)*qw,x,1),x,1),0,L));
The value W6 is left as symbolic without the integrals being solved, this means that when I pass the W6 term into the time integration in a separate script and solve for qw terms the time integration is much slower because it is computing the spatial integration in X for each time of the 1000 time-steps.
I have tried using the ‘double’,’simplify’ and ‘collect’ commands but I have not been able to get the result in the form I want it. So what I’m asking is, is there a way to "force" matlab to do the integrations with the symbolic coefficients attahced. Any help would be much appreciated! Hi All,
I am trying to perform a definite integration in X (length axis) to calculate some beam modeshapes, following this the variables will be passed into a time integration using ode45. In the integration there are beam modeshape terms (W) which are a function of x and there are time dependent terms (qw) which are not. Crucially the qw terms are not commutable so cannot be factored out of the integrals. I need the answer to W6 to be given in terms W6=Y1*qw1+Y2*qw2… where Y1 and Y2 are numerical coefficients.
Here is my code:
clear all
clc
syms x qw1 qw2
L=0.52;
qw=[qw1; qw2];
%Bending Mode
Landa=[1.875104069 4.694091133];% 7.854757];% 10.99554];
for j=1:length(Landa)
SIGMA(j)=(cos(Landa(j))+cosh(Landa(j)))/(sin(Landa(j))+sinh(Landa(j)));
W(j)=cosh(Landa(j)*x/L)-cos(Landa(j)*x/L)-SIGMA(j)*(sinh(Landa(j)*x/L)-sin(Landa(j)*x/L));
end
% Integration in X over length of beam
W6=(vpaintegral(W*diff(diff(W,x,1)*qw*diff(diff(W,x,1)*qw*diff(W,x,2)*qw,x,1),x,1),0,L));
The value W6 is left as symbolic without the integrals being solved, this means that when I pass the W6 term into the time integration in a separate script and solve for qw terms the time integration is much slower because it is computing the spatial integration in X for each time of the 1000 time-steps.
I have tried using the ‘double’,’simplify’ and ‘collect’ commands but I have not been able to get the result in the form I want it. So what I’m asking is, is there a way to "force" matlab to do the integrations with the symbolic coefficients attahced. Any help would be much appreciated! definite integration, symbolic toolbox, simplifying MATLAB Answers — New Questions
Non-linear scaling for linear increase in complexity
I have a class which defines an array and then loops over this array updating each element in turn. If I change the length of the array linearly the runtime increases non-linearly. Why? I must be missing something silly.
classdef C
properties
N uint32 {mustBeInteger, mustBePositive}
x (1, 🙂 {mustBeFloat, mustBeNonnegative} = []
end
methods
function c = C(N)
arguments
N uint32 {mustBeInteger, mustBePositive}
end
c.N = N;
c.x = zeros(1, c.N);
end
function run(c)
arguments
c C
end
for i = 1:c.N
c.x(i) = 1;
end
end
end
end
N_range = 1e4:1e4:1e5;
times = zeros(1, length(N_range));
N_i = 1;
for N = N_range
c = C(N);
tic
c.run();
times(N_i) = toc;
N_i = N_i + 1;
end
plot(times)I have a class which defines an array and then loops over this array updating each element in turn. If I change the length of the array linearly the runtime increases non-linearly. Why? I must be missing something silly.
classdef C
properties
N uint32 {mustBeInteger, mustBePositive}
x (1, 🙂 {mustBeFloat, mustBeNonnegative} = []
end
methods
function c = C(N)
arguments
N uint32 {mustBeInteger, mustBePositive}
end
c.N = N;
c.x = zeros(1, c.N);
end
function run(c)
arguments
c C
end
for i = 1:c.N
c.x(i) = 1;
end
end
end
end
N_range = 1e4:1e4:1e5;
times = zeros(1, length(N_range));
N_i = 1;
for N = N_range
c = C(N);
tic
c.run();
times(N_i) = toc;
N_i = N_i + 1;
end
plot(times) I have a class which defines an array and then loops over this array updating each element in turn. If I change the length of the array linearly the runtime increases non-linearly. Why? I must be missing something silly.
classdef C
properties
N uint32 {mustBeInteger, mustBePositive}
x (1, 🙂 {mustBeFloat, mustBeNonnegative} = []
end
methods
function c = C(N)
arguments
N uint32 {mustBeInteger, mustBePositive}
end
c.N = N;
c.x = zeros(1, c.N);
end
function run(c)
arguments
c C
end
for i = 1:c.N
c.x(i) = 1;
end
end
end
end
N_range = 1e4:1e4:1e5;
times = zeros(1, length(N_range));
N_i = 1;
for N = N_range
c = C(N);
tic
c.run();
times(N_i) = toc;
N_i = N_i + 1;
end
plot(times) complexity, validation, overhead, speed, performance MATLAB Answers — New Questions
I have this system of linear equations and i need to solve it for unknowns. how i can solve it in MATLAB? we have 8 unknowns and 8 equations.
$$
begin{aligned}
& b_{0}^{l}=a_{0}^{l} A_{00}^{l}+sum_{n=a_{n}}^{infty} a_{n}^{l} A_{0} n^{ell}+Z_{0}^{l} \
& b_{m}^{l}=a_{0}^{l} A_{m 0}^{l}+sum_{n=1}^{infty} a_{n}^{l} A_{m n}^{l}+Z_{m}^{l} \
& a_{0}^{l}=b_{0}^{l} B_{00}^{l}+sum_{m=1}^{infty} b_{m}{ }^{l} B_{0 m}^{l}+c_{0}^{l} C_{00}^{l}+sum_{m=1}^{infty} c_{m}^{l} C_{0 m}^{l}+Y_{0}^{l} \
& a_{n}^{l}=b_{0}^{l} B_{n 0}^{l}+sum_{m=1}^{infty} b_{m}^{l} B_{n m}^{l}+c_{0}^{l} C_{n 0}^{l}+sum_{m=1}^{infty} c_{m}^{l} C_{n m}^{l}+Y_{n}^{l}
end{aligned}
$$
and:
$$
begin{aligned}
& c_{0}^{l}=d_{0}^{l} D_{00}^{ell}+sum_{n=1}^{infty} d_{n}^{l} D_{0 n}^{l}+X_{0}^{l} \
& c_{m}^{l}=d_{0}^{l} D_{m 0}^{ell}+sum_{n=1}^{infty} d_{n}^{l} D_{m n}^{ell}+X_{m}^{ell} \
& d_{0}^{ell} = b_{0}^{l} E_{00}^{ell}+sum_{m=1}^{infty} b_{m}^{ell} E_{0 m}^{l}+c_{0}^{l} F_{00}^{l}+sum_{m=1}^{infty} c_{m}^{l} F_{0 m}^{l}+W_{0}^{l} \
& d_{n}^{l}=b_{0}^{l} E_{n 0}^{l}+sum_{m=1}^{infty} b_{m}^{l} E_{n m}^{l}+c_{0}^{l} F_{n 0}^{l}+sum_{m=1}^{infty} c_{m}^{l} F_{n m}^{l}+W_{n}^{l}
end{aligned}
$$
Unknowns are:-
$$
begin{gathered}
left(a_{0}^{l}, a_{n}^{l}right) ;left(b_{0}^{l}, b_{n}^{l}right),left(c_{0}^{l}, c_{n}^{l}right) and \
left(d_{0}^{l}, d_{n}^{l}right) .
end{gathered}
$$
The above system of equations which is linear one is the latex code for these equations and i need to solve it for these unknowns. I am confused that how i can solved this system. how i can write these equations in matrix form to solved it for the unknowns? Help me.$$
begin{aligned}
& b_{0}^{l}=a_{0}^{l} A_{00}^{l}+sum_{n=a_{n}}^{infty} a_{n}^{l} A_{0} n^{ell}+Z_{0}^{l} \
& b_{m}^{l}=a_{0}^{l} A_{m 0}^{l}+sum_{n=1}^{infty} a_{n}^{l} A_{m n}^{l}+Z_{m}^{l} \
& a_{0}^{l}=b_{0}^{l} B_{00}^{l}+sum_{m=1}^{infty} b_{m}{ }^{l} B_{0 m}^{l}+c_{0}^{l} C_{00}^{l}+sum_{m=1}^{infty} c_{m}^{l} C_{0 m}^{l}+Y_{0}^{l} \
& a_{n}^{l}=b_{0}^{l} B_{n 0}^{l}+sum_{m=1}^{infty} b_{m}^{l} B_{n m}^{l}+c_{0}^{l} C_{n 0}^{l}+sum_{m=1}^{infty} c_{m}^{l} C_{n m}^{l}+Y_{n}^{l}
end{aligned}
$$
and:
$$
begin{aligned}
& c_{0}^{l}=d_{0}^{l} D_{00}^{ell}+sum_{n=1}^{infty} d_{n}^{l} D_{0 n}^{l}+X_{0}^{l} \
& c_{m}^{l}=d_{0}^{l} D_{m 0}^{ell}+sum_{n=1}^{infty} d_{n}^{l} D_{m n}^{ell}+X_{m}^{ell} \
& d_{0}^{ell} = b_{0}^{l} E_{00}^{ell}+sum_{m=1}^{infty} b_{m}^{ell} E_{0 m}^{l}+c_{0}^{l} F_{00}^{l}+sum_{m=1}^{infty} c_{m}^{l} F_{0 m}^{l}+W_{0}^{l} \
& d_{n}^{l}=b_{0}^{l} E_{n 0}^{l}+sum_{m=1}^{infty} b_{m}^{l} E_{n m}^{l}+c_{0}^{l} F_{n 0}^{l}+sum_{m=1}^{infty} c_{m}^{l} F_{n m}^{l}+W_{n}^{l}
end{aligned}
$$
Unknowns are:-
$$
begin{gathered}
left(a_{0}^{l}, a_{n}^{l}right) ;left(b_{0}^{l}, b_{n}^{l}right),left(c_{0}^{l}, c_{n}^{l}right) and \
left(d_{0}^{l}, d_{n}^{l}right) .
end{gathered}
$$
The above system of equations which is linear one is the latex code for these equations and i need to solve it for these unknowns. I am confused that how i can solved this system. how i can write these equations in matrix form to solved it for the unknowns? Help me. $$
begin{aligned}
& b_{0}^{l}=a_{0}^{l} A_{00}^{l}+sum_{n=a_{n}}^{infty} a_{n}^{l} A_{0} n^{ell}+Z_{0}^{l} \
& b_{m}^{l}=a_{0}^{l} A_{m 0}^{l}+sum_{n=1}^{infty} a_{n}^{l} A_{m n}^{l}+Z_{m}^{l} \
& a_{0}^{l}=b_{0}^{l} B_{00}^{l}+sum_{m=1}^{infty} b_{m}{ }^{l} B_{0 m}^{l}+c_{0}^{l} C_{00}^{l}+sum_{m=1}^{infty} c_{m}^{l} C_{0 m}^{l}+Y_{0}^{l} \
& a_{n}^{l}=b_{0}^{l} B_{n 0}^{l}+sum_{m=1}^{infty} b_{m}^{l} B_{n m}^{l}+c_{0}^{l} C_{n 0}^{l}+sum_{m=1}^{infty} c_{m}^{l} C_{n m}^{l}+Y_{n}^{l}
end{aligned}
$$
and:
$$
begin{aligned}
& c_{0}^{l}=d_{0}^{l} D_{00}^{ell}+sum_{n=1}^{infty} d_{n}^{l} D_{0 n}^{l}+X_{0}^{l} \
& c_{m}^{l}=d_{0}^{l} D_{m 0}^{ell}+sum_{n=1}^{infty} d_{n}^{l} D_{m n}^{ell}+X_{m}^{ell} \
& d_{0}^{ell} = b_{0}^{l} E_{00}^{ell}+sum_{m=1}^{infty} b_{m}^{ell} E_{0 m}^{l}+c_{0}^{l} F_{00}^{l}+sum_{m=1}^{infty} c_{m}^{l} F_{0 m}^{l}+W_{0}^{l} \
& d_{n}^{l}=b_{0}^{l} E_{n 0}^{l}+sum_{m=1}^{infty} b_{m}^{l} E_{n m}^{l}+c_{0}^{l} F_{n 0}^{l}+sum_{m=1}^{infty} c_{m}^{l} F_{n m}^{l}+W_{n}^{l}
end{aligned}
$$
Unknowns are:-
$$
begin{gathered}
left(a_{0}^{l}, a_{n}^{l}right) ;left(b_{0}^{l}, b_{n}^{l}right),left(c_{0}^{l}, c_{n}^{l}right) and \
left(d_{0}^{l}, d_{n}^{l}right) .
end{gathered}
$$
The above system of equations which is linear one is the latex code for these equations and i need to solve it for these unknowns. I am confused that how i can solved this system. how i can write these equations in matrix form to solved it for the unknowns? Help me. system of equations MATLAB Answers — New Questions
How can i change rotation axis?
Rotation axis normally defined axis around Z,I want to rotate my modal around x and y axis how can i change rotation axis of the revolute joint?
ThanksRotation axis normally defined axis around Z,I want to rotate my modal around x and y axis how can i change rotation axis of the revolute joint?
Thanks Rotation axis normally defined axis around Z,I want to rotate my modal around x and y axis how can i change rotation axis of the revolute joint?
Thanks rotation, axis, simmechanics MATLAB Answers — New Questions
How do I find the number of circles in an image? I’ve given the code I used and output image below
clc;
close all;
clear all;
a=imread(‘C:UsersHemaDesktopnonemptylot.jpg’);
b=imread(‘C:UsersHemaDesktopemptylot.jpg’);
[x,y]= size(a);
[c d]=size(b);
e=rgb2hsv(a);
f=rgb2hsv(b);
subplot(1,2,1)
imshow(e);
title(‘HSV of Nonempty’);
centers = imfindcircles(e,[20 20]);
[centers,radii] = imfindcircles(e,[5 15]);
[centers,radii,metric] = imfindcircles(e,[5 15]);
BW=size(viscircles(centers, radii,’EdgeColor’,’b’));
STATS = regionprops(BW,’EquivDiameter’);
subplot(1,2,2)
imshow(f);
title(‘HSV of empty’);
centers = imfindcircles(f,[20 20]);
[centers,radii] = imfindcircles(f,[5 15]);
[centers,radii,metric] = imfindcircles(f,[5 15]);
BW=size(viscircles(centers, radii,’EdgeColor’,’b’));
STATS = regionprops(BW,’EquivDiameter’);
disp(STATS);clc;
close all;
clear all;
a=imread(‘C:UsersHemaDesktopnonemptylot.jpg’);
b=imread(‘C:UsersHemaDesktopemptylot.jpg’);
[x,y]= size(a);
[c d]=size(b);
e=rgb2hsv(a);
f=rgb2hsv(b);
subplot(1,2,1)
imshow(e);
title(‘HSV of Nonempty’);
centers = imfindcircles(e,[20 20]);
[centers,radii] = imfindcircles(e,[5 15]);
[centers,radii,metric] = imfindcircles(e,[5 15]);
BW=size(viscircles(centers, radii,’EdgeColor’,’b’));
STATS = regionprops(BW,’EquivDiameter’);
subplot(1,2,2)
imshow(f);
title(‘HSV of empty’);
centers = imfindcircles(f,[20 20]);
[centers,radii] = imfindcircles(f,[5 15]);
[centers,radii,metric] = imfindcircles(f,[5 15]);
BW=size(viscircles(centers, radii,’EdgeColor’,’b’));
STATS = regionprops(BW,’EquivDiameter’);
disp(STATS); clc;
close all;
clear all;
a=imread(‘C:UsersHemaDesktopnonemptylot.jpg’);
b=imread(‘C:UsersHemaDesktopemptylot.jpg’);
[x,y]= size(a);
[c d]=size(b);
e=rgb2hsv(a);
f=rgb2hsv(b);
subplot(1,2,1)
imshow(e);
title(‘HSV of Nonempty’);
centers = imfindcircles(e,[20 20]);
[centers,radii] = imfindcircles(e,[5 15]);
[centers,radii,metric] = imfindcircles(e,[5 15]);
BW=size(viscircles(centers, radii,’EdgeColor’,’b’));
STATS = regionprops(BW,’EquivDiameter’);
subplot(1,2,2)
imshow(f);
title(‘HSV of empty’);
centers = imfindcircles(f,[20 20]);
[centers,radii] = imfindcircles(f,[5 15]);
[centers,radii,metric] = imfindcircles(f,[5 15]);
BW=size(viscircles(centers, radii,’EdgeColor’,’b’));
STATS = regionprops(BW,’EquivDiameter’);
disp(STATS); circles, finding number of objects, image processing MATLAB Answers — New Questions
How to put a legend outside of a tiled layout graph?
I am trying to create some graphs, and I am struggling to put the legend where I want it in my graph. I would like my graph to look like this:
However, the code that i have wrtiien:
%%% plot mean and SD:
s = sprintf(‘[%c]’, char(176)); % degree angle symbol
figure
title(‘Mean and SD’)
ax1=subplot(4,1,1);
fontsize=get(ax1, ‘FontSize’);
title(‘Start’)
hold on
[m,n] = size(DATA1start);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA1start’,2,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
[m,n] = size(DATA2start);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA2start’,2,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)%stdshade(DATA2start’,’0.3′,’b’)
hold on
[m,n] = size(DATA3start);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA3start’,2,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
hold on
scatter(1:101,mean(DATA1start’,’omitnan’),10,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22")
hold on
scatter(1:101,mean(DATA2start’,’omitnan’),10,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7")
hold on
scatter(1:101,mean(DATA3start’,’omitnan’),10,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09")
ylabel([‘Angular Difference’, s])
xlabel([‘Percentage of gait cycle (%)’])
xlim([0 100])
ylim([0 60])
% Create fake points for the legend
hFakeDATA1 = plot(NaN, NaN, ‘o’, ‘MarkerFaceColor’, "#228b22", ‘MarkerEdgeColor’, "#228b22", ‘MarkerSize’, 5);
hFakeDATA2 = plot(NaN, NaN, ‘o’, ‘MarkerFaceColor’, "#395dc7", ‘MarkerEdgeColor’, "#395dc7", ‘MarkerSize’, 5);
hFakeDATA3 = plot(NaN, NaN, ‘o’, ‘MarkerFaceColor’, "#f88f09", ‘MarkerEdgeColor’, "#f88f09", ‘MarkerSize’, 5);
% Create fake entry for the shaded region
hShadedRegion = plot(NaN, NaN, ‘s’, ‘MarkerFaceColor’, [0.7 0.7 0.7], ‘MarkerEdgeColor’, ‘none’, ‘MarkerSize’, 8);
% Create custom legend with the fake points
legend([hFakeDATA1, hFakeDATA2, hFakeDATA3, hShadedRegion], …
{‘DATA1’, ‘DATA2’, ‘DATA3’, ‘Main effect of group’}, ‘Location’, ‘bestoutside’);
subplot(4,1,2)
title(‘Middle’)
hold on
[m,n] = size(DATA1middle);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA1middle’,2,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
[m,n] = size(DATA2middle);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA2middle’,2,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)%stdshade(DATA2start’,’0.3′,’b’)
hold on
[m,n] = size(DATA3middle);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA3middle’,2,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
hold on
scatter(1:101,mean(DATA1middle’,’omitnan’),10,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22")
hold on
scatter(1:101,mean(DATA2middle’,’omitnan’),10,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7")
hold on
scatter(1:101,mean(DATA3middle’,’omitnan’),10,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09")
ylabel([‘Angular Difference’, s])
xlabel([‘Percentage of gait cycle (%)’])
xlim([0 100])
ylim([0 60])
subplot(4,1,3)
title(‘End’)
hold on
[m,n] = size(DATA1last);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA1last’,2,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
[m,n] = size(DATA2last);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA2last’,2,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)%stdshade(DATA2start’,’0.3′,’b’)
hold on
[m,n] = size(DATA3last);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA3last’,2,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
hold on
scatter(1:101,mean(DATA1last’,’omitnan’),10,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22")
hold on
scatter(1:101,mean(DATA2last’,’omitnan’),10,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7")
hold on
scatter(1:101,mean(DATA3last’,’omitnan’),10,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09")
ylabel([‘Angular Difference’, s])
xlabel([‘Percentage of gait cycle (%)’])
xlim([0 100])
ylim([0 60])
Provides me with the graph shown here. I can’t seem to put the legend in the correct place ( I have moved the block of code around to create the legend before and after each graph, but with no success). I would like the legend to be outside of all the tiles! Any advice would be much appreciated :)I am trying to create some graphs, and I am struggling to put the legend where I want it in my graph. I would like my graph to look like this:
However, the code that i have wrtiien:
%%% plot mean and SD:
s = sprintf(‘[%c]’, char(176)); % degree angle symbol
figure
title(‘Mean and SD’)
ax1=subplot(4,1,1);
fontsize=get(ax1, ‘FontSize’);
title(‘Start’)
hold on
[m,n] = size(DATA1start);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA1start’,2,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
[m,n] = size(DATA2start);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA2start’,2,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)%stdshade(DATA2start’,’0.3′,’b’)
hold on
[m,n] = size(DATA3start);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA3start’,2,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
hold on
scatter(1:101,mean(DATA1start’,’omitnan’),10,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22")
hold on
scatter(1:101,mean(DATA2start’,’omitnan’),10,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7")
hold on
scatter(1:101,mean(DATA3start’,’omitnan’),10,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09")
ylabel([‘Angular Difference’, s])
xlabel([‘Percentage of gait cycle (%)’])
xlim([0 100])
ylim([0 60])
% Create fake points for the legend
hFakeDATA1 = plot(NaN, NaN, ‘o’, ‘MarkerFaceColor’, "#228b22", ‘MarkerEdgeColor’, "#228b22", ‘MarkerSize’, 5);
hFakeDATA2 = plot(NaN, NaN, ‘o’, ‘MarkerFaceColor’, "#395dc7", ‘MarkerEdgeColor’, "#395dc7", ‘MarkerSize’, 5);
hFakeDATA3 = plot(NaN, NaN, ‘o’, ‘MarkerFaceColor’, "#f88f09", ‘MarkerEdgeColor’, "#f88f09", ‘MarkerSize’, 5);
% Create fake entry for the shaded region
hShadedRegion = plot(NaN, NaN, ‘s’, ‘MarkerFaceColor’, [0.7 0.7 0.7], ‘MarkerEdgeColor’, ‘none’, ‘MarkerSize’, 8);
% Create custom legend with the fake points
legend([hFakeDATA1, hFakeDATA2, hFakeDATA3, hShadedRegion], …
{‘DATA1’, ‘DATA2’, ‘DATA3’, ‘Main effect of group’}, ‘Location’, ‘bestoutside’);
subplot(4,1,2)
title(‘Middle’)
hold on
[m,n] = size(DATA1middle);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA1middle’,2,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
[m,n] = size(DATA2middle);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA2middle’,2,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)%stdshade(DATA2start’,’0.3′,’b’)
hold on
[m,n] = size(DATA3middle);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA3middle’,2,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
hold on
scatter(1:101,mean(DATA1middle’,’omitnan’),10,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22")
hold on
scatter(1:101,mean(DATA2middle’,’omitnan’),10,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7")
hold on
scatter(1:101,mean(DATA3middle’,’omitnan’),10,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09")
ylabel([‘Angular Difference’, s])
xlabel([‘Percentage of gait cycle (%)’])
xlim([0 100])
ylim([0 60])
subplot(4,1,3)
title(‘End’)
hold on
[m,n] = size(DATA1last);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA1last’,2,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
[m,n] = size(DATA2last);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA2last’,2,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)%stdshade(DATA2start’,’0.3′,’b’)
hold on
[m,n] = size(DATA3last);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA3last’,2,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
hold on
scatter(1:101,mean(DATA1last’,’omitnan’),10,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22")
hold on
scatter(1:101,mean(DATA2last’,’omitnan’),10,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7")
hold on
scatter(1:101,mean(DATA3last’,’omitnan’),10,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09")
ylabel([‘Angular Difference’, s])
xlabel([‘Percentage of gait cycle (%)’])
xlim([0 100])
ylim([0 60])
Provides me with the graph shown here. I can’t seem to put the legend in the correct place ( I have moved the block of code around to create the legend before and after each graph, but with no success). I would like the legend to be outside of all the tiles! Any advice would be much appreciated 🙂 I am trying to create some graphs, and I am struggling to put the legend where I want it in my graph. I would like my graph to look like this:
However, the code that i have wrtiien:
%%% plot mean and SD:
s = sprintf(‘[%c]’, char(176)); % degree angle symbol
figure
title(‘Mean and SD’)
ax1=subplot(4,1,1);
fontsize=get(ax1, ‘FontSize’);
title(‘Start’)
hold on
[m,n] = size(DATA1start);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA1start’,2,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
[m,n] = size(DATA2start);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA2start’,2,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)%stdshade(DATA2start’,’0.3′,’b’)
hold on
[m,n] = size(DATA3start);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA3start’,2,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
hold on
scatter(1:101,mean(DATA1start’,’omitnan’),10,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22")
hold on
scatter(1:101,mean(DATA2start’,’omitnan’),10,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7")
hold on
scatter(1:101,mean(DATA3start’,’omitnan’),10,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09")
ylabel([‘Angular Difference’, s])
xlabel([‘Percentage of gait cycle (%)’])
xlim([0 100])
ylim([0 60])
% Create fake points for the legend
hFakeDATA1 = plot(NaN, NaN, ‘o’, ‘MarkerFaceColor’, "#228b22", ‘MarkerEdgeColor’, "#228b22", ‘MarkerSize’, 5);
hFakeDATA2 = plot(NaN, NaN, ‘o’, ‘MarkerFaceColor’, "#395dc7", ‘MarkerEdgeColor’, "#395dc7", ‘MarkerSize’, 5);
hFakeDATA3 = plot(NaN, NaN, ‘o’, ‘MarkerFaceColor’, "#f88f09", ‘MarkerEdgeColor’, "#f88f09", ‘MarkerSize’, 5);
% Create fake entry for the shaded region
hShadedRegion = plot(NaN, NaN, ‘s’, ‘MarkerFaceColor’, [0.7 0.7 0.7], ‘MarkerEdgeColor’, ‘none’, ‘MarkerSize’, 8);
% Create custom legend with the fake points
legend([hFakeDATA1, hFakeDATA2, hFakeDATA3, hShadedRegion], …
{‘DATA1’, ‘DATA2’, ‘DATA3’, ‘Main effect of group’}, ‘Location’, ‘bestoutside’);
subplot(4,1,2)
title(‘Middle’)
hold on
[m,n] = size(DATA1middle);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA1middle’,2,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
[m,n] = size(DATA2middle);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA2middle’,2,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)%stdshade(DATA2start’,’0.3′,’b’)
hold on
[m,n] = size(DATA3middle);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA3middle’,2,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
hold on
scatter(1:101,mean(DATA1middle’,’omitnan’),10,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22")
hold on
scatter(1:101,mean(DATA2middle’,’omitnan’),10,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7")
hold on
scatter(1:101,mean(DATA3middle’,’omitnan’),10,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09")
ylabel([‘Angular Difference’, s])
xlabel([‘Percentage of gait cycle (%)’])
xlim([0 100])
ylim([0 60])
subplot(4,1,3)
title(‘End’)
hold on
[m,n] = size(DATA1last);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA1last’,2,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
[m,n] = size(DATA2last);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA2last’,2,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)%stdshade(DATA2start’,’0.3′,’b’)
hold on
[m,n] = size(DATA3last);
xaxis=repmat(1:101, n, 1);
scatter(xaxis,DATA3last’,2,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09", ‘MarkerFaceAlpha’,.3,’MarkerEdgeAlpha’,.3)
hold on
scatter(1:101,mean(DATA1last’,’omitnan’),10,’MarkerFaceColor’,"#228b22",’MarkerEdgeColor’,"#228b22")
hold on
scatter(1:101,mean(DATA2last’,’omitnan’),10,’MarkerFaceColor’,"#395dc7",’MarkerEdgeColor’,"#395dc7")
hold on
scatter(1:101,mean(DATA3last’,’omitnan’),10,’MarkerFaceColor’,"#f88f09",’MarkerEdgeColor’,"#f88f09")
ylabel([‘Angular Difference’, s])
xlabel([‘Percentage of gait cycle (%)’])
xlim([0 100])
ylim([0 60])
Provides me with the graph shown here. I can’t seem to put the legend in the correct place ( I have moved the block of code around to create the legend before and after each graph, but with no success). I would like the legend to be outside of all the tiles! Any advice would be much appreciated 🙂 scatter, legend, tiledlayout, location, bestoutside MATLAB Answers — New Questions
how can I save a variable to an excel file?
Hi,
I have a complex variable (named "ST_normalized") in my MATLAB code. I want to save that file to an Excel file. Can you please help me with that? Thanks for your time.
regardsHi,
I have a complex variable (named "ST_normalized") in my MATLAB code. I want to save that file to an Excel file. Can you please help me with that? Thanks for your time.
regards Hi,
I have a complex variable (named "ST_normalized") in my MATLAB code. I want to save that file to an Excel file. Can you please help me with that? Thanks for your time.
regards matlab, figure, save, variable MATLAB Answers — New Questions
Optimization method based on the Nonlinear least squares as well as fmincon for the defined objective function (Non-linear function).
Hi there,
I am currently working on a Matlab code for my task (optimization task), and I tried two different methods;
Method A: the fmincon was used to minimize the objective function in which different algorithms, such as interior-point, sqp, sqp-legacy, interior-point, and active-set, were applied.
Method B: Nonlinear least squares optimization was combined with three algorithms, levenberg-marquardt, and trust-region-reflective.
The best results I got now are (from the Nonlinear least squares optimization + ‘interior-point’):
RMSE for X, Y, Z Direction(mm) : [1.18, 0.16, 1.33] mm; however, I want to reduce it as far as it is possible.
@ A quick guide for the code, and how it works.
1. I do have 3D data sets, and I used some mathematical methods to convert these 3D data into 2D data (Step 3).
2. The goal is to use some inverse method to get the same 3D datasets; therefore, after defining the objective function, I applied different optimization methods to address this task.
Any assistance or alternative approaches would be greatly appreciated.
Thank you in advance!
% @ Payam Samadi (2025.3.15) NLSP (Nonlinear least squares optimization)
% In step 3, the 2D projection data was extracted from the 3D data at
% different projections.
% In step4, the objective function is defined.
% In step 5, the Nonlinear least squares optimization is used to minimize
% the objective function.
% Algorithm:
% 1. ‘levenberg-marquardt’ : [1.21, 0.17, 1.39] mm,
% 2. ‘trust-region-reflective’ : [1.21, 0.17, 1.39] mm,
% 3. ‘interior-point’ : [1.18, 0.16, 1.33] mm
% Note: It is important to carefully consider the initial guesses for
% target locations, as well as the lower bounds (lb) and upper bounds (ub).
tic;
clc;
clear;
close all;
%% Step 1: Load xls file (3D Tumor position)
Load_Data = xlsread(‘Sample 1.xlsx’); % Data include 12 (sec)
% Load_Data = xlsread(‘Sample 2.xlsx’); % Data include 60 (sec)
Time = Load_Data(:,1); % Time (s)
xt=Load_Data(:,2); % xt for targets
yt=Load_Data(:,3); % yt for targets
zt=Load_Data(:,4); % zt for targets
true_T=[xt,yt,zt]; % target locations
[~,numT]=size(true_T); % number of targets
%% Step 2: Define imaging system parameters
SAD = 100; % source-axis distance (cm)
SID = 150; % source-image plane distance (cm)
num_projections = length(Time); % number of different views
% Generate projection angles
alpha = linspace(0, 360, num_projections);
% alpha=30;
theta_rad = deg2rad(alpha); % view angles (radians)
%% Step 3: Projection Model: Compute 2D projections
Xp=zeros(1,num_projections); % allocate array
Yp=zeros(1,num_projections);
for i=1:num_projections
f_theta = (SAD – (true_T(i,1) .* sin(theta_rad(i)) + true_T(i,3) .* cos(theta_rad(i)))) ./ SID;
Xp(1, i) = (true_T(i,1) .* cos(theta_rad(i)) – true_T(i,3) .* sin(theta_rad(i))) ./ f_theta;
Yp(1, i) = true_T(i,2) ./ f_theta;
end
xp = Xp’;
yp = Yp’;
%% Step 4: Define the objective function
% Define the objective function
objFun = @(T) computeProjectionError(T, xp, yp, theta_rad, SAD, SID, num_projections);
%% Step 5: Minimize the objective function using lsqnonlin
% Algorithm:
% 1. ‘levenberg-marquardt’ : [1.21, 0.17, 1.39] mm,
% 2. ‘trust-region-reflective’ : [1.21, 0.17, 1.39] mm,
% 3. ‘interior-point’ : [1.18, 0.16, 1.33] mm
% Define bounds
lb = []; % Lower bounds
ub = []; % Upper bounds
% Define optimization options
options = optimoptions(‘lsqnonlin’, …
‘Algorithm’, ‘interior-point’, …
‘Display’, ‘iter’, …
‘MaxIterations’, 300, …
‘MaxFunctionEvaluations’, 20000, …
‘TolFun’, 1e-10, …
‘TolX’, 1e-10, …
‘StepTolerance’, 1e-8, …
‘FiniteDifferenceStepSize’, 1e-3, …
‘UseParallel’, true);
% Generate a better initial guess
T0 = ones(3, num_projections);
% Run optimization for each projection
estimated_T = zeros(3, num_projections);
for i = 1:num_projections
objFun_i = @(T) computeProjectionError(T, xp(i), yp(i), theta_rad(i), SAD, SID, 1);
estimated_T(:, i) = lsqnonlin(objFun_i, T0(:, i), lb, ub, options);
end
%% Step 6: Calculate RMSE value
% Estimated Tumor Position in X, Y, and Z Direction
Estimate_3D_X = estimated_T(1,:);
Estimate_3D_Y = estimated_T(2,:);
Estimate_3D_Z = estimated_T(3,:);
RMSE_x = Calculate_RMSR (xt,Estimate_3D_X);
RMSE_y = Calculate_RMSR (yt,Estimate_3D_Y);
RMSE_z = Calculate_RMSR (zt,Estimate_3D_Z);
fprintf([‘RMSE for X, Y, Z Direction(mm): ‘ …
‘[%.2f, %.2f, %.2f] mmn’], RMSE_x, RMSE_y, RMSE_z);
%% Step 7: Plot Estimated vs Real Data
Plot_results (Time, xt, yt, zt, Estimate_3D_X, Estimate_3D_Y, Estimate_3D_Z);
toc;
%% Objective function: Computes error between observed and estimated projections
function error = computeProjectionError(T, xp, yp, theta_rad, SAD, SID, num_projections)
for i=1:num_projections
x_est = T(1,:);
y_est = T(2,:);
z_est = T(3,:);
% Compute estimated projection using the perspective transformation
f_theta = (SAD – (x_est(i) .* sin(theta_rad(i)) + z_est(i) .* cos(theta_rad(i))))./ SID;
xp_est(i) = (x_est(i) .* cos(theta_rad(i)) – z_est(i) .* sin(theta_rad(i))) ./ f_theta;
yp_est(i) = y_est(i) ./ f_theta;
end
%% Compute residual error (Method 1)
% Compute the residual error
error_x = xp – xp_est;
error_y = yp – yp_est;
% Return residuals for least squares minimization
error = [error_x; error_y];
end
function RMSE = Calculate_RMSR (True_value,Estimated_value)
% Calculate RMSE
e1 = (True_value(:)-Estimated_value(:)).^2;
RMSE = sqrt(mean(e1,’omitnan’));
end
function Plot_results (Time, xt, yt, zt, Estimate_3D_X, Estimate_3D_Y, Estimate_3D_Z)
figure(‘WindowState’, ‘maximized’)
subplot(3,1,1);
plot(Time, Estimate_3D_X,’r’);
hold on;
plot(Time, xt,’b’);
legend (‘Estimate’, ‘Real’);
title (‘X Dierction’)
xlabel (‘Time (s)’);
ylabel (‘Motion (mm)’)
hold off;
subplot(3,1,2);
plot(Time, Estimate_3D_Y,’r’);
hold on;
plot(Time, yt,’b’);
legend (‘Estimate’, ‘Real’);
title (‘Y Dierction’)
xlabel (‘Time (s)’);
ylabel (‘Motion (mm)’)
hold off;
subplot(3,1,3);
plot(Time, Estimate_3D_Z,’r’);
hold on;
plot(Time, zt,’b’);
legend (‘Estimate’, ‘Real’);
title (‘Z Dierction’)
xlabel (‘Time (s)’);
ylabel (‘Motion (mm)’)
hold off;
endHi there,
I am currently working on a Matlab code for my task (optimization task), and I tried two different methods;
Method A: the fmincon was used to minimize the objective function in which different algorithms, such as interior-point, sqp, sqp-legacy, interior-point, and active-set, were applied.
Method B: Nonlinear least squares optimization was combined with three algorithms, levenberg-marquardt, and trust-region-reflective.
The best results I got now are (from the Nonlinear least squares optimization + ‘interior-point’):
RMSE for X, Y, Z Direction(mm) : [1.18, 0.16, 1.33] mm; however, I want to reduce it as far as it is possible.
@ A quick guide for the code, and how it works.
1. I do have 3D data sets, and I used some mathematical methods to convert these 3D data into 2D data (Step 3).
2. The goal is to use some inverse method to get the same 3D datasets; therefore, after defining the objective function, I applied different optimization methods to address this task.
Any assistance or alternative approaches would be greatly appreciated.
Thank you in advance!
% @ Payam Samadi (2025.3.15) NLSP (Nonlinear least squares optimization)
% In step 3, the 2D projection data was extracted from the 3D data at
% different projections.
% In step4, the objective function is defined.
% In step 5, the Nonlinear least squares optimization is used to minimize
% the objective function.
% Algorithm:
% 1. ‘levenberg-marquardt’ : [1.21, 0.17, 1.39] mm,
% 2. ‘trust-region-reflective’ : [1.21, 0.17, 1.39] mm,
% 3. ‘interior-point’ : [1.18, 0.16, 1.33] mm
% Note: It is important to carefully consider the initial guesses for
% target locations, as well as the lower bounds (lb) and upper bounds (ub).
tic;
clc;
clear;
close all;
%% Step 1: Load xls file (3D Tumor position)
Load_Data = xlsread(‘Sample 1.xlsx’); % Data include 12 (sec)
% Load_Data = xlsread(‘Sample 2.xlsx’); % Data include 60 (sec)
Time = Load_Data(:,1); % Time (s)
xt=Load_Data(:,2); % xt for targets
yt=Load_Data(:,3); % yt for targets
zt=Load_Data(:,4); % zt for targets
true_T=[xt,yt,zt]; % target locations
[~,numT]=size(true_T); % number of targets
%% Step 2: Define imaging system parameters
SAD = 100; % source-axis distance (cm)
SID = 150; % source-image plane distance (cm)
num_projections = length(Time); % number of different views
% Generate projection angles
alpha = linspace(0, 360, num_projections);
% alpha=30;
theta_rad = deg2rad(alpha); % view angles (radians)
%% Step 3: Projection Model: Compute 2D projections
Xp=zeros(1,num_projections); % allocate array
Yp=zeros(1,num_projections);
for i=1:num_projections
f_theta = (SAD – (true_T(i,1) .* sin(theta_rad(i)) + true_T(i,3) .* cos(theta_rad(i)))) ./ SID;
Xp(1, i) = (true_T(i,1) .* cos(theta_rad(i)) – true_T(i,3) .* sin(theta_rad(i))) ./ f_theta;
Yp(1, i) = true_T(i,2) ./ f_theta;
end
xp = Xp’;
yp = Yp’;
%% Step 4: Define the objective function
% Define the objective function
objFun = @(T) computeProjectionError(T, xp, yp, theta_rad, SAD, SID, num_projections);
%% Step 5: Minimize the objective function using lsqnonlin
% Algorithm:
% 1. ‘levenberg-marquardt’ : [1.21, 0.17, 1.39] mm,
% 2. ‘trust-region-reflective’ : [1.21, 0.17, 1.39] mm,
% 3. ‘interior-point’ : [1.18, 0.16, 1.33] mm
% Define bounds
lb = []; % Lower bounds
ub = []; % Upper bounds
% Define optimization options
options = optimoptions(‘lsqnonlin’, …
‘Algorithm’, ‘interior-point’, …
‘Display’, ‘iter’, …
‘MaxIterations’, 300, …
‘MaxFunctionEvaluations’, 20000, …
‘TolFun’, 1e-10, …
‘TolX’, 1e-10, …
‘StepTolerance’, 1e-8, …
‘FiniteDifferenceStepSize’, 1e-3, …
‘UseParallel’, true);
% Generate a better initial guess
T0 = ones(3, num_projections);
% Run optimization for each projection
estimated_T = zeros(3, num_projections);
for i = 1:num_projections
objFun_i = @(T) computeProjectionError(T, xp(i), yp(i), theta_rad(i), SAD, SID, 1);
estimated_T(:, i) = lsqnonlin(objFun_i, T0(:, i), lb, ub, options);
end
%% Step 6: Calculate RMSE value
% Estimated Tumor Position in X, Y, and Z Direction
Estimate_3D_X = estimated_T(1,:);
Estimate_3D_Y = estimated_T(2,:);
Estimate_3D_Z = estimated_T(3,:);
RMSE_x = Calculate_RMSR (xt,Estimate_3D_X);
RMSE_y = Calculate_RMSR (yt,Estimate_3D_Y);
RMSE_z = Calculate_RMSR (zt,Estimate_3D_Z);
fprintf([‘RMSE for X, Y, Z Direction(mm): ‘ …
‘[%.2f, %.2f, %.2f] mmn’], RMSE_x, RMSE_y, RMSE_z);
%% Step 7: Plot Estimated vs Real Data
Plot_results (Time, xt, yt, zt, Estimate_3D_X, Estimate_3D_Y, Estimate_3D_Z);
toc;
%% Objective function: Computes error between observed and estimated projections
function error = computeProjectionError(T, xp, yp, theta_rad, SAD, SID, num_projections)
for i=1:num_projections
x_est = T(1,:);
y_est = T(2,:);
z_est = T(3,:);
% Compute estimated projection using the perspective transformation
f_theta = (SAD – (x_est(i) .* sin(theta_rad(i)) + z_est(i) .* cos(theta_rad(i))))./ SID;
xp_est(i) = (x_est(i) .* cos(theta_rad(i)) – z_est(i) .* sin(theta_rad(i))) ./ f_theta;
yp_est(i) = y_est(i) ./ f_theta;
end
%% Compute residual error (Method 1)
% Compute the residual error
error_x = xp – xp_est;
error_y = yp – yp_est;
% Return residuals for least squares minimization
error = [error_x; error_y];
end
function RMSE = Calculate_RMSR (True_value,Estimated_value)
% Calculate RMSE
e1 = (True_value(:)-Estimated_value(:)).^2;
RMSE = sqrt(mean(e1,’omitnan’));
end
function Plot_results (Time, xt, yt, zt, Estimate_3D_X, Estimate_3D_Y, Estimate_3D_Z)
figure(‘WindowState’, ‘maximized’)
subplot(3,1,1);
plot(Time, Estimate_3D_X,’r’);
hold on;
plot(Time, xt,’b’);
legend (‘Estimate’, ‘Real’);
title (‘X Dierction’)
xlabel (‘Time (s)’);
ylabel (‘Motion (mm)’)
hold off;
subplot(3,1,2);
plot(Time, Estimate_3D_Y,’r’);
hold on;
plot(Time, yt,’b’);
legend (‘Estimate’, ‘Real’);
title (‘Y Dierction’)
xlabel (‘Time (s)’);
ylabel (‘Motion (mm)’)
hold off;
subplot(3,1,3);
plot(Time, Estimate_3D_Z,’r’);
hold on;
plot(Time, zt,’b’);
legend (‘Estimate’, ‘Real’);
title (‘Z Dierction’)
xlabel (‘Time (s)’);
ylabel (‘Motion (mm)’)
hold off;
end Hi there,
I am currently working on a Matlab code for my task (optimization task), and I tried two different methods;
Method A: the fmincon was used to minimize the objective function in which different algorithms, such as interior-point, sqp, sqp-legacy, interior-point, and active-set, were applied.
Method B: Nonlinear least squares optimization was combined with three algorithms, levenberg-marquardt, and trust-region-reflective.
The best results I got now are (from the Nonlinear least squares optimization + ‘interior-point’):
RMSE for X, Y, Z Direction(mm) : [1.18, 0.16, 1.33] mm; however, I want to reduce it as far as it is possible.
@ A quick guide for the code, and how it works.
1. I do have 3D data sets, and I used some mathematical methods to convert these 3D data into 2D data (Step 3).
2. The goal is to use some inverse method to get the same 3D datasets; therefore, after defining the objective function, I applied different optimization methods to address this task.
Any assistance or alternative approaches would be greatly appreciated.
Thank you in advance!
% @ Payam Samadi (2025.3.15) NLSP (Nonlinear least squares optimization)
% In step 3, the 2D projection data was extracted from the 3D data at
% different projections.
% In step4, the objective function is defined.
% In step 5, the Nonlinear least squares optimization is used to minimize
% the objective function.
% Algorithm:
% 1. ‘levenberg-marquardt’ : [1.21, 0.17, 1.39] mm,
% 2. ‘trust-region-reflective’ : [1.21, 0.17, 1.39] mm,
% 3. ‘interior-point’ : [1.18, 0.16, 1.33] mm
% Note: It is important to carefully consider the initial guesses for
% target locations, as well as the lower bounds (lb) and upper bounds (ub).
tic;
clc;
clear;
close all;
%% Step 1: Load xls file (3D Tumor position)
Load_Data = xlsread(‘Sample 1.xlsx’); % Data include 12 (sec)
% Load_Data = xlsread(‘Sample 2.xlsx’); % Data include 60 (sec)
Time = Load_Data(:,1); % Time (s)
xt=Load_Data(:,2); % xt for targets
yt=Load_Data(:,3); % yt for targets
zt=Load_Data(:,4); % zt for targets
true_T=[xt,yt,zt]; % target locations
[~,numT]=size(true_T); % number of targets
%% Step 2: Define imaging system parameters
SAD = 100; % source-axis distance (cm)
SID = 150; % source-image plane distance (cm)
num_projections = length(Time); % number of different views
% Generate projection angles
alpha = linspace(0, 360, num_projections);
% alpha=30;
theta_rad = deg2rad(alpha); % view angles (radians)
%% Step 3: Projection Model: Compute 2D projections
Xp=zeros(1,num_projections); % allocate array
Yp=zeros(1,num_projections);
for i=1:num_projections
f_theta = (SAD – (true_T(i,1) .* sin(theta_rad(i)) + true_T(i,3) .* cos(theta_rad(i)))) ./ SID;
Xp(1, i) = (true_T(i,1) .* cos(theta_rad(i)) – true_T(i,3) .* sin(theta_rad(i))) ./ f_theta;
Yp(1, i) = true_T(i,2) ./ f_theta;
end
xp = Xp’;
yp = Yp’;
%% Step 4: Define the objective function
% Define the objective function
objFun = @(T) computeProjectionError(T, xp, yp, theta_rad, SAD, SID, num_projections);
%% Step 5: Minimize the objective function using lsqnonlin
% Algorithm:
% 1. ‘levenberg-marquardt’ : [1.21, 0.17, 1.39] mm,
% 2. ‘trust-region-reflective’ : [1.21, 0.17, 1.39] mm,
% 3. ‘interior-point’ : [1.18, 0.16, 1.33] mm
% Define bounds
lb = []; % Lower bounds
ub = []; % Upper bounds
% Define optimization options
options = optimoptions(‘lsqnonlin’, …
‘Algorithm’, ‘interior-point’, …
‘Display’, ‘iter’, …
‘MaxIterations’, 300, …
‘MaxFunctionEvaluations’, 20000, …
‘TolFun’, 1e-10, …
‘TolX’, 1e-10, …
‘StepTolerance’, 1e-8, …
‘FiniteDifferenceStepSize’, 1e-3, …
‘UseParallel’, true);
% Generate a better initial guess
T0 = ones(3, num_projections);
% Run optimization for each projection
estimated_T = zeros(3, num_projections);
for i = 1:num_projections
objFun_i = @(T) computeProjectionError(T, xp(i), yp(i), theta_rad(i), SAD, SID, 1);
estimated_T(:, i) = lsqnonlin(objFun_i, T0(:, i), lb, ub, options);
end
%% Step 6: Calculate RMSE value
% Estimated Tumor Position in X, Y, and Z Direction
Estimate_3D_X = estimated_T(1,:);
Estimate_3D_Y = estimated_T(2,:);
Estimate_3D_Z = estimated_T(3,:);
RMSE_x = Calculate_RMSR (xt,Estimate_3D_X);
RMSE_y = Calculate_RMSR (yt,Estimate_3D_Y);
RMSE_z = Calculate_RMSR (zt,Estimate_3D_Z);
fprintf([‘RMSE for X, Y, Z Direction(mm): ‘ …
‘[%.2f, %.2f, %.2f] mmn’], RMSE_x, RMSE_y, RMSE_z);
%% Step 7: Plot Estimated vs Real Data
Plot_results (Time, xt, yt, zt, Estimate_3D_X, Estimate_3D_Y, Estimate_3D_Z);
toc;
%% Objective function: Computes error between observed and estimated projections
function error = computeProjectionError(T, xp, yp, theta_rad, SAD, SID, num_projections)
for i=1:num_projections
x_est = T(1,:);
y_est = T(2,:);
z_est = T(3,:);
% Compute estimated projection using the perspective transformation
f_theta = (SAD – (x_est(i) .* sin(theta_rad(i)) + z_est(i) .* cos(theta_rad(i))))./ SID;
xp_est(i) = (x_est(i) .* cos(theta_rad(i)) – z_est(i) .* sin(theta_rad(i))) ./ f_theta;
yp_est(i) = y_est(i) ./ f_theta;
end
%% Compute residual error (Method 1)
% Compute the residual error
error_x = xp – xp_est;
error_y = yp – yp_est;
% Return residuals for least squares minimization
error = [error_x; error_y];
end
function RMSE = Calculate_RMSR (True_value,Estimated_value)
% Calculate RMSE
e1 = (True_value(:)-Estimated_value(:)).^2;
RMSE = sqrt(mean(e1,’omitnan’));
end
function Plot_results (Time, xt, yt, zt, Estimate_3D_X, Estimate_3D_Y, Estimate_3D_Z)
figure(‘WindowState’, ‘maximized’)
subplot(3,1,1);
plot(Time, Estimate_3D_X,’r’);
hold on;
plot(Time, xt,’b’);
legend (‘Estimate’, ‘Real’);
title (‘X Dierction’)
xlabel (‘Time (s)’);
ylabel (‘Motion (mm)’)
hold off;
subplot(3,1,2);
plot(Time, Estimate_3D_Y,’r’);
hold on;
plot(Time, yt,’b’);
legend (‘Estimate’, ‘Real’);
title (‘Y Dierction’)
xlabel (‘Time (s)’);
ylabel (‘Motion (mm)’)
hold off;
subplot(3,1,3);
plot(Time, Estimate_3D_Z,’r’);
hold on;
plot(Time, zt,’b’);
legend (‘Estimate’, ‘Real’);
title (‘Z Dierction’)
xlabel (‘Time (s)’);
ylabel (‘Motion (mm)’)
hold off;
end optimization, fmincon, nonlinear least squares, objective function MATLAB Answers — New Questions
trouver un angle avec l’equation de trajectoire d’un projectile
Bonjour, j’ai un probleme avec ma conception d’un projet de cours j’aimerais calculé l’angle adequat pour mon projectile avec un x0 et y0 en fonction de x mais matlab me donne aucune reponse. voici ce que je recois comme resultat. merciBonjour, j’ai un probleme avec ma conception d’un projet de cours j’aimerais calculé l’angle adequat pour mon projectile avec un x0 et y0 en fonction de x mais matlab me donne aucune reponse. voici ce que je recois comme resultat. merci Bonjour, j’ai un probleme avec ma conception d’un projet de cours j’aimerais calculé l’angle adequat pour mon projectile avec un x0 et y0 en fonction de x mais matlab me donne aucune reponse. voici ce que je recois comme resultat. merci symbolic, trigonometric MATLAB Answers — New Questions
GPU code generation failed with the error ’emlc:compilationError’
When using GPU Coder, I encountered issues with the following environment configuration:
– **GPU Version**: NVIDIA RTX A2000 (Compute Capability 8.6, Ampere Architecture).
– **MATLAB Version**: R2023b.
– **CUDA Toolkit Version**: 11.8.
– **Visual Studio Version**: 2022 (with "Desktop Development with C++" component installed).
When I test
gpuDevice
ans =
CUDADevice – 属性:
Name: ‘NVIDIA RTX A2000’
Index: 1
ComputeCapability: ‘8.6’
SupportsDouble: 1
GraphicsDriverVersion: ‘572.83’
DriverModel: ‘WDDM’
ToolkitVersion: 11.8000
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152 (49.15 KB)
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 6435504128 (6.44 GB)
AvailableMemory: 5375778816 (5.38 GB)
CachePolicy: ‘balanced’
MultiprocessorCount: 26
ClockRateKHz: 1200000
ComputeMode: ‘Default’
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceAvailable: 1
DeviceSelected: 1
If I test coder.checkGpuInstall
coder.checkGpuInstall:
Compatible GPU : PASSED
CUDA Environment : PASSED
Runtime : PASSED
cuFFT : PASSED
cuSOLVER : PASSED
cuBLAS : PASSED
cuDNN Environment : FAILED (Error generated while determining cuDNN library version ‘Embedding metadata in the MEX file failed.
‘.)
Host Compiler : PASSED
Basic Code Generation : FAILED (GPU code generation failed with the error ’emlc:compilationError’. View report for further information: View report)
ans =
包含以下字段的 struct:
gpu: 1
cuda: 1
cudnn: 0
tensorrt: 0
hostcompiler: 1
basiccodegen: 0
basiccodeexec: 0
deepcodegen: 0
deepcodeexec: 0
tensorrtdatatype: 0
profiling: 0
test mex -setup
mex -setup
MEX 配置为使用 ‘MinGW64 Compiler (C)’ 以进行 C 语言编译。
要选择不同的 C 编译器,请从以下选项中选择一种命令:
MinGW64 Compiler (C) mex -setup:C:Users石海洋AppDataRoamingMathWorksMATLABR2023bmex_C_win64.xml C
Microsoft Visual C++ 2022 (C) mex -setup:’D:Program FilesMathWorksR2023Bbinwin64mexoptsmsvc2022.xml’ C
要选择不同的语言,请从以下选项中选择一种命令:
mex -setup C++
mex -setup FORTRAN
I looked throught the answers about ’emlc:compilationError’ and "Invalid CUDA device", and see the answer in GPU coder :basic Code Generation failed – MATLAB Answers – MATLAB Central, its issue is caused by a MATLAB version that is too low. However, after reviewing the relevant settings, my MATLAB version should support CUDA 11.8 and VS2022. So, what could be the problem?
PS: I installed cuDNN 8.9 (cudnn-windows-x86_64-8.9.7.29_cuda11-archive) and set the system environment variable `NVIDIA_CUDNN` to: `C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.8`. Why does the cuDNN Environment still show as failed here?When using GPU Coder, I encountered issues with the following environment configuration:
– **GPU Version**: NVIDIA RTX A2000 (Compute Capability 8.6, Ampere Architecture).
– **MATLAB Version**: R2023b.
– **CUDA Toolkit Version**: 11.8.
– **Visual Studio Version**: 2022 (with "Desktop Development with C++" component installed).
When I test
gpuDevice
ans =
CUDADevice – 属性:
Name: ‘NVIDIA RTX A2000’
Index: 1
ComputeCapability: ‘8.6’
SupportsDouble: 1
GraphicsDriverVersion: ‘572.83’
DriverModel: ‘WDDM’
ToolkitVersion: 11.8000
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152 (49.15 KB)
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 6435504128 (6.44 GB)
AvailableMemory: 5375778816 (5.38 GB)
CachePolicy: ‘balanced’
MultiprocessorCount: 26
ClockRateKHz: 1200000
ComputeMode: ‘Default’
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceAvailable: 1
DeviceSelected: 1
If I test coder.checkGpuInstall
coder.checkGpuInstall:
Compatible GPU : PASSED
CUDA Environment : PASSED
Runtime : PASSED
cuFFT : PASSED
cuSOLVER : PASSED
cuBLAS : PASSED
cuDNN Environment : FAILED (Error generated while determining cuDNN library version ‘Embedding metadata in the MEX file failed.
‘.)
Host Compiler : PASSED
Basic Code Generation : FAILED (GPU code generation failed with the error ’emlc:compilationError’. View report for further information: View report)
ans =
包含以下字段的 struct:
gpu: 1
cuda: 1
cudnn: 0
tensorrt: 0
hostcompiler: 1
basiccodegen: 0
basiccodeexec: 0
deepcodegen: 0
deepcodeexec: 0
tensorrtdatatype: 0
profiling: 0
test mex -setup
mex -setup
MEX 配置为使用 ‘MinGW64 Compiler (C)’ 以进行 C 语言编译。
要选择不同的 C 编译器,请从以下选项中选择一种命令:
MinGW64 Compiler (C) mex -setup:C:Users石海洋AppDataRoamingMathWorksMATLABR2023bmex_C_win64.xml C
Microsoft Visual C++ 2022 (C) mex -setup:’D:Program FilesMathWorksR2023Bbinwin64mexoptsmsvc2022.xml’ C
要选择不同的语言,请从以下选项中选择一种命令:
mex -setup C++
mex -setup FORTRAN
I looked throught the answers about ’emlc:compilationError’ and "Invalid CUDA device", and see the answer in GPU coder :basic Code Generation failed – MATLAB Answers – MATLAB Central, its issue is caused by a MATLAB version that is too low. However, after reviewing the relevant settings, my MATLAB version should support CUDA 11.8 and VS2022. So, what could be the problem?
PS: I installed cuDNN 8.9 (cudnn-windows-x86_64-8.9.7.29_cuda11-archive) and set the system environment variable `NVIDIA_CUDNN` to: `C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.8`. Why does the cuDNN Environment still show as failed here? When using GPU Coder, I encountered issues with the following environment configuration:
– **GPU Version**: NVIDIA RTX A2000 (Compute Capability 8.6, Ampere Architecture).
– **MATLAB Version**: R2023b.
– **CUDA Toolkit Version**: 11.8.
– **Visual Studio Version**: 2022 (with "Desktop Development with C++" component installed).
When I test
gpuDevice
ans =
CUDADevice – 属性:
Name: ‘NVIDIA RTX A2000’
Index: 1
ComputeCapability: ‘8.6’
SupportsDouble: 1
GraphicsDriverVersion: ‘572.83’
DriverModel: ‘WDDM’
ToolkitVersion: 11.8000
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152 (49.15 KB)
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 6435504128 (6.44 GB)
AvailableMemory: 5375778816 (5.38 GB)
CachePolicy: ‘balanced’
MultiprocessorCount: 26
ClockRateKHz: 1200000
ComputeMode: ‘Default’
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceAvailable: 1
DeviceSelected: 1
If I test coder.checkGpuInstall
coder.checkGpuInstall:
Compatible GPU : PASSED
CUDA Environment : PASSED
Runtime : PASSED
cuFFT : PASSED
cuSOLVER : PASSED
cuBLAS : PASSED
cuDNN Environment : FAILED (Error generated while determining cuDNN library version ‘Embedding metadata in the MEX file failed.
‘.)
Host Compiler : PASSED
Basic Code Generation : FAILED (GPU code generation failed with the error ’emlc:compilationError’. View report for further information: View report)
ans =
包含以下字段的 struct:
gpu: 1
cuda: 1
cudnn: 0
tensorrt: 0
hostcompiler: 1
basiccodegen: 0
basiccodeexec: 0
deepcodegen: 0
deepcodeexec: 0
tensorrtdatatype: 0
profiling: 0
test mex -setup
mex -setup
MEX 配置为使用 ‘MinGW64 Compiler (C)’ 以进行 C 语言编译。
要选择不同的 C 编译器,请从以下选项中选择一种命令:
MinGW64 Compiler (C) mex -setup:C:Users石海洋AppDataRoamingMathWorksMATLABR2023bmex_C_win64.xml C
Microsoft Visual C++ 2022 (C) mex -setup:’D:Program FilesMathWorksR2023Bbinwin64mexoptsmsvc2022.xml’ C
要选择不同的语言,请从以下选项中选择一种命令:
mex -setup C++
mex -setup FORTRAN
I looked throught the answers about ’emlc:compilationError’ and "Invalid CUDA device", and see the answer in GPU coder :basic Code Generation failed – MATLAB Answers – MATLAB Central, its issue is caused by a MATLAB version that is too low. However, after reviewing the relevant settings, my MATLAB version should support CUDA 11.8 and VS2022. So, what could be the problem?
PS: I installed cuDNN 8.9 (cudnn-windows-x86_64-8.9.7.29_cuda11-archive) and set the system environment variable `NVIDIA_CUDNN` to: `C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.8`. Why does the cuDNN Environment still show as failed here? gpu coder, basic code generation MATLAB Answers — New Questions
How can I generate trajectory and INS data from the GPS data I have?
I want to generate the trajectory using the GPS data I have in LLA (deg deg m).
Then I want to generate the IMU data from that trajectory.
My end goal is to apply insmargfilter to pose the Estimation and Orientation for a UAV in MATLAB.I want to generate the trajectory using the GPS data I have in LLA (deg deg m).
Then I want to generate the IMU data from that trajectory.
My end goal is to apply insmargfilter to pose the Estimation and Orientation for a UAV in MATLAB. I want to generate the trajectory using the GPS data I have in LLA (deg deg m).
Then I want to generate the IMU data from that trajectory.
My end goal is to apply insmargfilter to pose the Estimation and Orientation for a UAV in MATLAB. inertial navigation, gps, localisation, ins MATLAB Answers — New Questions
How do I check which universities has a campus wide license
I wanted to check if my university has a license for it login into the account does not seem like it. But surely I am doing something wrong because my mail works with almost everything that has a student plan. How can I check if my university is on the list or if not how can I get my university on itI wanted to check if my university has a license for it login into the account does not seem like it. But surely I am doing something wrong because my mail works with almost everything that has a student plan. How can I check if my university is on the list or if not how can I get my university on it I wanted to check if my university has a license for it login into the account does not seem like it. But surely I am doing something wrong because my mail works with almost everything that has a student plan. How can I check if my university is on the list or if not how can I get my university on it license MATLAB Answers — New Questions
sine wave measure differ
function y = generate_sine()
persistent t
Ts = 0.0001;
if isempty(t)
t = 0;
end
y = sin(377 * t);
t = t + Ts;
This is sine wave generator of 60 Hz.
when the scope set up is below, that isnt 60 Hz.
but same code, that is same function block and measure with sine wave block of 60 Hz , then measure 60 Hz
why?function y = generate_sine()
persistent t
Ts = 0.0001;
if isempty(t)
t = 0;
end
y = sin(377 * t);
t = t + Ts;
This is sine wave generator of 60 Hz.
when the scope set up is below, that isnt 60 Hz.
but same code, that is same function block and measure with sine wave block of 60 Hz , then measure 60 Hz
why? function y = generate_sine()
persistent t
Ts = 0.0001;
if isempty(t)
t = 0;
end
y = sin(377 * t);
t = t + Ts;
This is sine wave generator of 60 Hz.
when the scope set up is below, that isnt 60 Hz.
but same code, that is same function block and measure with sine wave block of 60 Hz , then measure 60 Hz
why? sine, simulink MATLAB Answers — New Questions