Author: PuTI
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
How the Google-Wiz acquisition redefines cloud security
Google’s acquisition of Wiz, announced last week, is a pivotal moment as it marks a strategic shift in how cyber security will evolve over the next few years. It instantly turns Google into a major player in security, adding Wiz to other building blocks Google has racked up in the past couple of years, most notably Mandiant and Google Chronicle.
Google’s acquisition of Wiz, announced last week, is a pivotal moment as it marks a strategic shift in how cyber security will evolve over the next few years. It instantly turns Google into a major player in security, adding Wiz to other building blocks Google has racked up in the past couple of years, most notably Mandiant and Google Chronicle.
Read More
Microsoft at 50: The journey and future of the partner ecosystem
As we celebrate Microsoft’s 50th anniversary, our annual State of the Partner Ecosystem moment is a great opportunity to reflect on the incredible journey we’ve shared with our partners, employees and customers. Together, we’ve harnessed technology as a force for good, transforming industries and communities. From our early days of revolutionizing personal computing to leading the way in cloud innovation and now AI, our shared milestones highlight the power of collaboration and reinvention.
Fifty years ago, Microsoft started with a bold idea: the belief that technology could change the world. Thanks to the largest partner ecosystem in the industry, numbering 500,000 and growing, that vision became a reality, and I know we are just getting started. From the early days of distributing Windows PCs and Office to now delivering AI transformation strategies that solve the most complex customer challenges, our ability to stay at the forefront of innovation as technology evolves is a testament to our culture of continuous reinvention.
According to IDC, for every $1 of Microsoft revenue, services partners earn $8.45, and software partners earn $10.93. This underscores the immense opportunity available to partners of all types. As we look ahead to the future, we know that generative AI (GenAI) is forecast to grow exponentially faster than the overall IT market. Partners generating at least 25% of their Microsoft-related revenue from AI can expect higher margins and revenue growth, unlocking even more potential for transformation and success.*
Microsoft has always been a partner-led company. Our partners are core to our heritage and our future. Their innovation and collaboration have driven real transformation and customer success and will continue to shape the future of industries around the world. As we commemorate this historic moment, I want to take the opportunity to say Thank You to our partners for being on this incredible journey with us.
Here are just a few ways you can join us to celebrate this milestone:
- Watch this video from Judson Althoff, Executive Vice President and Chief Commercial Officer, Microsoft.
- Join the Microsoft AI Skills Fest for 50 days of learning and discovery starting April 8! Gain skills that will empower you and your team to build innovative AI solutions with Microsoft’s apps and services.
“For decades, Intel’s partnership with Microsoft has sparked innovation and delivered value to our customers. Together, we’ve revolutionized industries and established new benchmarks for excellence. We look forward to collaborating for the next 50 years — and beyond.”
— Jim Johnson, Senior Vice President, Client Computing Group, Intel
Preparing for the future with the Microsoft AI Cloud Partner Program (MAICPP)
Microsoft succeeds when our partners succeed. MAICPP has evolved to enable partners worldwide to deliver customer outcomes across every industry, from small businesses to the largest enterprises. Our program is designed to provide our partners with the most relevant tools and resources they need to thrive in a rapidly changing market, and it serves as the home for all partner types.
“As a proud Microsoft alum, I’ve seen firsthand how our collaboration has evolved to drive meaningful change for businesses across industries. From strategy through engineering and implementation, PwC and Microsoft drive innovation and deliver real business outcomes for clients worldwide.”
— Stephanie Mosticchio, Principal, US and Global Microsoft Alliance Leader, PwC
Through MAICPP, all partners can access updated benefits packages designed to accelerate growth and meet specific business needs. Software development companies are encouraged to explore ISV Success, a pathway offering additional benefits to expand development capabilities and shorten time to market. Whether building, publishing or growing sales, partners can leverage targeted offers to get the support they need.
“As someone who has led global partnerships at several of the world’s leading technology companies, I am impressed by how Microsoft has leaned in with their partner ecosystem and taken a leadership position in cloud computing and AI. We, at Snowflake, are excited to continue to strengthen our partnership in the years to come, and we look forward to jointly driving customer success in the age of enterprise AI. Congratulations!
— Tyler Prince, Senior Vice President of Worldwide Alliances & Channels, Snowflake
Depending on business goals, partners may pursue a Solutions Partner designation or specialization, both of which provide tailored benefits to help differentiate their business in a competitive market. Achieving a designation unlocks valuable go-to-market resources, sales support, new incentives and product benefits to help expand customer reach, sharpen skills and drive growth. For software development companies, becoming a Solutions Partner** with certified software*** further enhances market presence by validating software capabilities in high-demand areas.
“Having worked alongside every CEO of Microsoft in my career, I would like to personally congratulate Microsoft for its 50 extraordinary years of driving relentless innovation.”
“Lenovo is proud to be a major part of this amazing journey with Microsoft and we are committed to this partnership for many more decades to come.”
— Yuanqing Yang, Chairman and Chief Executive Officer, Lenovo
For partners holding an Azure designation or Azure specialization, additional incentives are available through Azure Migrate and Modernize and Azure Innovate — both underpinned by Azure Essentials. With comprehensive resources, extensive coverage across scenarios and tailored incentives in one easy-to-navigate hub, Azure partners can better support customers from migration to innovation. Learn more in What’s new for Azure partner-led offerings: ISV Success and specialization updates.
Our program offers benefits for partners aligned to their growth stage and across all customer segments. We have recently made the process of obtaining an Azure Solutions Partner designation more aligned to our partners who specialize in working with small and midsize customers. We are also expanding access to Azure Migrate and Modernize and Azure Innovate incentives for SMB pathways. Read more about the SMB path to Azure Solutions Partner designations.
Cloud Solution Provider is our partner hero motion for small and medium enterprises
In November at Microsoft Ignite, we highlighted the $661 billion total addressable market (TAM) opportunity for SME&C customers in FY25 and beyond. Cloud Solution Provider (CSP) partners are the trusted advisors who serve these customers and accelerate their AI transformation with the value-added services and solutions that create real business impact. CSP is our hero motion that enables those partners to drive this business transformation.
“Our Microsoft partnership has evolved to meet the needs of our business and our partners. Together we’ve been able to support our partners to deliver true solution and value selling, leveraging the robust resources available through Microsoft AI Cloud Partner Program and benefitting from the rich incentives. It has enabled us to drive innovation and deliver exceptional experiences for our partners through our ArrowSphere platform and broader enablement programs to ensure they’re empowered to deliver real customer outcomes. Together, we’re enabling the channel to deliver solutions that deliver real impact for customers around the world.”
— Brendan Murphy, Global Director, Public Cloud, Arrow Electronics
We strive to provide CSP partners with the skilling, capabilities and investments to make this opportunity a reality. So far in FY25, we have:
- focused our incentives to clearly align to our five strategic priorities — Copilot on every device across every role, AI design wins with every customer, securing the cyber foundation of every customer, a focus on migrations and Microsoft 365 execution
- dedicated 70% of our total incentive spend to partners that serve the Small and Medium Enterprise and Customer (SME&C) segment
- introduced a series of new promos, including a new-to-Microsoft 365 E5 offer to enable CSP partners to win new customers
Expanding our portfolio of CSP offers and capabilities is an ongoing priority. We share updates as they become available.
Capturing the marketplace opportunity
As customers increasingly centralize their solution procurement, marketplaces have become the preferred buying platform. For software companies, adopting cloud marketplaces accelerates deal closure and increases deal sizes. Serving as a global B2B commerce engine, our marketplace empowers Microsoft partners to provide solutions to customers worldwide. It offers various sales models: digital direct, through partners or with Microsoft — providing flexibility to align with how customers want to buy and how partners want to sell. Learn more in this recent blog.
Unlocking success through skilling and events
The speed of technology innovation requires continuous learning. To support this, we offer our partners a variety of skilling opportunities, such as our popular in-person Microsoft AI Partner Training Days, designed to help partners develop both technical and sales capabilities.
We are also streamlining and simplifying our skilling portals through initiatives like Microsoft Sales Titan (currently in private preview for CSP Accelerate partners and available for all partners in summer 2025), a program tailored to equip sales professionals with in-depth knowledge of Microsoft Threat Protection SKUs, empowering them to position themselves as industry leaders. Discover these and other skilling opportunities.
Looking ahead, we invite our partners to join us at Microsoft Build, taking place May 19–22, 2025. This flagship event offers an exclusive opportunity to explore the latest advancements in AI, learn how to work smarter and elevate your projects. Connect with peers, industry experts and Microsoft leadership while diving into the code and innovations that will shape the future.
“Schneider Electric and Microsoft have been driven by a shared vision of a world that is more electric and digital. We’re thrilled to celebrate Microsoft’s 50th anniversary and excited to continue pioneering innovative solutions together, harnessing the transformative power of AI, pushing the boundaries of what’s possible for our customers and shaping a sustainable future for generations to come.”
— Frédéric Godemel, Executive Vice President, Energy Management, Schneider Electric
Looking forward – the next 50 years
As we celebrate this remarkable milestone, we remain focused on and optimistic for the future. We continue to innovate, collaborate and empower our partners to thrive in the era of AI and beyond. The past 50 years have been defined by shared success, and this will continue for our future. Together, we will unlock new opportunities, drive transformation and shape the future of technology.
Throughout this journey, stories of innovation have inspired us. A few examples of how partners are celebrating our 50th anniversary are included in this blog. See the full list of partner quotes on the Microsoft 50th Anniversary celebration site.
Thank you for being an integral part of our story. We can’t wait to see what we’ll accomplish together next!
*IDC: Microsoft Partners: Driving Economic Value and AI Maturity
**“Solutions Partner” refers to a company that is a member of the Microsoft AI Cloud Partner Program and may offer software, services, and/or solutions to customers. Reference to “Solutions Partner” in any content, materials, resources, web properties, etc. and any associated designation should be not interpreted as an offer, endorsement, guarantee, proof of effectiveness or functionality, a commitment or any other type of representation or warranty on the part of Microsoft. All decisions pertaining to and related to your business needs including but not limited to strategies, solutions, partner selection, implementation, etc. rest solely with your business.
***A certification is (A) specific to the solution’s interoperability with Microsoft products and (B) based on self-attestation by the solution owner. Solutions are only certified as of the date the solution is reviewed. Solution functionality and capability are controlled by the solution owner and may be subject to change. The inclusion of a solution in marketplace and any such designations should not be interpreted as an offer, endorsement, guarantee, proof of effectiveness or functionality, a commitment or any other type of representation or warranty on the part of Microsoft. All decisions pertaining and related to your business needs including but not limited to strategies, solutions, partner selection, implementation, etc. rest solely with your business.
The post Microsoft at 50: The journey and future of the partner ecosystem appeared first on The Official Microsoft Blog.
As we celebrate Microsoft’s 50th anniversary, our annual State of the Partner Ecosystem moment is a great opportunity to reflect on the incredible journey we’ve shared with our partners, employees and customers. Together, we’ve harnessed technology as a force for good, transforming industries and communities. From our early days of revolutionizing personal computing to leading…
The post Microsoft at 50: The journey and future of the partner ecosystem appeared first on The Official Microsoft Blog.Read More
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
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
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