Author: PuTI
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
matlab simulink 대수루프 해결방법 문의
수소 탱크를 충전할 때 압력이 상승하여 탱크 내 온도가 상승하는데 외부로 열전달 현상을 통해서 열이 빠져나간다.
수소 탱크에 수소가 유입이 될 때 압력, 온도, 질량유량에 따라 내부 열전달 계수를 계산하고 반영해서 탱크에서의 온도를 예측하는 모델을 만들고 있는데 루프가 걸려서
블록 다이어그램 ‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b’에 1개의 대수 루프가 있습니다. 루프에 대한 자세한 내용을 보려면 명령 Simulink.BlockDiagram.getAlgebraicLoops(‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b’)을(를) 사용하거나 MATLAB 명령 창에 sldebug(‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b’)을(를) 입력하여 명령줄 Simulink 디버거를 사용하십시오. 이 메시지를 제거하려면 대수 루프를 "안 함"으로 설정하십시오.
구성요소:Simulink | 범주:Block diagram 경고
다음이 포함된 대수 루프가 발견됨: Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Power1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Sum1 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /PowerInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product2Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Sum2Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product5Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/PowerInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/LogInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Log1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product2Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product3Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/SquareInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/GainInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /SumInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product3Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ProductInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/Solver Configuration/EVAL_KEY/INPUT_1_1_1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/Solver Configuration/EVAL_KEY/STATE_1 (discontinuity) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/Solver Configuration/EVAL_KEY/OUTPUT_1_0Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Math FunctionInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/GainInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Math Function1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /k/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Cp/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Cp/ProductInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /mu/Gain1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product6 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /mu/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /rho/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /rho/Gain1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product4Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product5 (algebraic variable)
구성요소:Simulink | 범주:Model
대수 루프 내에서 불연속이 감지되었습니다. 해를 구하는 데 어려움이 있을 수 있습니다.
구성요소:Simulink | 범주:Model 경고
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product5’에 0으로 나누기 발생
구성요소:Simulink | 범주:Block 경고
표시 안 함
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Power’에 거듭제곱 결과가 정의되어 있지 않습니다.
구성요소:Simulink | 범주:Block 경고
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product1’에 0으로 나누기 발생
구성요소:Simulink | 범주:Block 경고
표시 안 함
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Log1’에 음수의 로그가 있습니다. ‘출력 신호 유형’을 복소수로 설정해 보십시오.
구성요소:Simulink | 범주:Block 경고
시뮬레이션을 실행하는 동안 오류가 발생하여 시뮬레이션이 종료되었습니다
원인:
시간 0.0에 계산된 ‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product’을(를) 포함하는 대수 루프의 대수 상태가 Inf 또는 NaN입니다. 해에 특이점이 있을 수 있습니다. 모델이 올바른 경우 고정 스텝 크기를 줄이거나 오차 허용오차를 좁혀 스텝 크기를 줄여 보십시오. 또는 대수 루프 변수 값의 초기 추측값을 조금 수정하십시오.
다음과 같은 오류가 뜬다.
압력과 온도는 물성값 구하기 위해 필요하고 질량유량은 Renolds number를 구하기 위해 필요하다.
Liner Thermal Mass, CFRP Thermal Mass, External Convective Heat Transfer, CFRP Conductive Heat Transfer 등등 블럭은 고정된 값을 사용해서 신경 안써도될 것 같다.
아래 사진은 simulink 설계도이다.수소 탱크를 충전할 때 압력이 상승하여 탱크 내 온도가 상승하는데 외부로 열전달 현상을 통해서 열이 빠져나간다.
수소 탱크에 수소가 유입이 될 때 압력, 온도, 질량유량에 따라 내부 열전달 계수를 계산하고 반영해서 탱크에서의 온도를 예측하는 모델을 만들고 있는데 루프가 걸려서
블록 다이어그램 ‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b’에 1개의 대수 루프가 있습니다. 루프에 대한 자세한 내용을 보려면 명령 Simulink.BlockDiagram.getAlgebraicLoops(‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b’)을(를) 사용하거나 MATLAB 명령 창에 sldebug(‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b’)을(를) 입력하여 명령줄 Simulink 디버거를 사용하십시오. 이 메시지를 제거하려면 대수 루프를 "안 함"으로 설정하십시오.
구성요소:Simulink | 범주:Block diagram 경고
다음이 포함된 대수 루프가 발견됨: Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Power1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Sum1 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /PowerInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product2Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Sum2Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product5Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/PowerInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/LogInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Log1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product2Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product3Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/SquareInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/GainInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /SumInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product3Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ProductInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/Solver Configuration/EVAL_KEY/INPUT_1_1_1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/Solver Configuration/EVAL_KEY/STATE_1 (discontinuity) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/Solver Configuration/EVAL_KEY/OUTPUT_1_0Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Math FunctionInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/GainInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Math Function1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /k/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Cp/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Cp/ProductInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /mu/Gain1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product6 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /mu/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /rho/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /rho/Gain1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product4Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product5 (algebraic variable)
구성요소:Simulink | 범주:Model
대수 루프 내에서 불연속이 감지되었습니다. 해를 구하는 데 어려움이 있을 수 있습니다.
구성요소:Simulink | 범주:Model 경고
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product5’에 0으로 나누기 발생
구성요소:Simulink | 범주:Block 경고
표시 안 함
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Power’에 거듭제곱 결과가 정의되어 있지 않습니다.
구성요소:Simulink | 범주:Block 경고
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product1’에 0으로 나누기 발생
구성요소:Simulink | 범주:Block 경고
표시 안 함
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Log1’에 음수의 로그가 있습니다. ‘출력 신호 유형’을 복소수로 설정해 보십시오.
구성요소:Simulink | 범주:Block 경고
시뮬레이션을 실행하는 동안 오류가 발생하여 시뮬레이션이 종료되었습니다
원인:
시간 0.0에 계산된 ‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product’을(를) 포함하는 대수 루프의 대수 상태가 Inf 또는 NaN입니다. 해에 특이점이 있을 수 있습니다. 모델이 올바른 경우 고정 스텝 크기를 줄이거나 오차 허용오차를 좁혀 스텝 크기를 줄여 보십시오. 또는 대수 루프 변수 값의 초기 추측값을 조금 수정하십시오.
다음과 같은 오류가 뜬다.
압력과 온도는 물성값 구하기 위해 필요하고 질량유량은 Renolds number를 구하기 위해 필요하다.
Liner Thermal Mass, CFRP Thermal Mass, External Convective Heat Transfer, CFRP Conductive Heat Transfer 등등 블럭은 고정된 값을 사용해서 신경 안써도될 것 같다.
아래 사진은 simulink 설계도이다. 수소 탱크를 충전할 때 압력이 상승하여 탱크 내 온도가 상승하는데 외부로 열전달 현상을 통해서 열이 빠져나간다.
수소 탱크에 수소가 유입이 될 때 압력, 온도, 질량유량에 따라 내부 열전달 계수를 계산하고 반영해서 탱크에서의 온도를 예측하는 모델을 만들고 있는데 루프가 걸려서
블록 다이어그램 ‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b’에 1개의 대수 루프가 있습니다. 루프에 대한 자세한 내용을 보려면 명령 Simulink.BlockDiagram.getAlgebraicLoops(‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b’)을(를) 사용하거나 MATLAB 명령 창에 sldebug(‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b’)을(를) 입력하여 명령줄 Simulink 디버거를 사용하십시오. 이 메시지를 제거하려면 대수 루프를 "안 함"으로 설정하십시오.
구성요소:Simulink | 범주:Block diagram 경고
다음이 포함된 대수 루프가 발견됨: Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Power1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Sum1 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /PowerInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product2Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Sum2Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product5Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/PowerInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/LogInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Log1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product2Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product3Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/SquareInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/GainInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /SumInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product3Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ProductInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/Solver Configuration/EVAL_KEY/INPUT_1_1_1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/Solver Configuration/EVAL_KEY/STATE_1 (discontinuity) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/Solver Configuration/EVAL_KEY/OUTPUT_1_0Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Math FunctionInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/GainInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Math Function1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /k/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Cp/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Cp/ProductInternal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /mu/Gain1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product6 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /mu/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /rho/Product7 (algebraic variable) Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /rho/Gain1Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product4Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product5 (algebraic variable)
구성요소:Simulink | 범주:Model
대수 루프 내에서 불연속이 감지되었습니다. 해를 구하는 데 어려움이 있을 수 있습니다.
구성요소:Simulink | 범주:Model 경고
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product5’에 0으로 나누기 발생
구성요소:Simulink | 범주:Block 경고
표시 안 함
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Power’에 거듭제곱 결과가 정의되어 있지 않습니다.
구성요소:Simulink | 범주:Block 경고
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Product1’에 0으로 나누기 발생
구성요소:Simulink | 범주:Block 경고
표시 안 함
‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Subsystem/Log1’에 음수의 로그가 있습니다. ‘출력 신호 유형’을 복소수로 설정해 보십시오.
구성요소:Simulink | 범주:Block 경고
시뮬레이션을 실행하는 동안 오류가 발생하여 시뮬레이션이 종료되었습니다
원인:
시간 0.0에 계산된 ‘Internal_Heat_Trasfer_Coefficient_Test_ver1_2023b/Subsystem/ /Product’을(를) 포함하는 대수 루프의 대수 상태가 Inf 또는 NaN입니다. 해에 특이점이 있을 수 있습니다. 모델이 올바른 경우 고정 스텝 크기를 줄이거나 오차 허용오차를 좁혀 스텝 크기를 줄여 보십시오. 또는 대수 루프 변수 값의 초기 추측값을 조금 수정하십시오.
다음과 같은 오류가 뜬다.
압력과 온도는 물성값 구하기 위해 필요하고 질량유량은 Renolds number를 구하기 위해 필요하다.
Liner Thermal Mass, CFRP Thermal Mass, External Convective Heat Transfer, CFRP Conductive Heat Transfer 등등 블럭은 고정된 값을 사용해서 신경 안써도될 것 같다.
아래 사진은 simulink 설계도이다. 수소충전, simulink, 대수루프 MATLAB Answers — New Questions
Debugging: Changing ode equation during integration
Hello everyone,
I’m imprementing an adjustment to my chemical reactor design regarding physical limitation, due to the kinetics the value of one specie goes negative (comuptationally correct, but not physically) to account for the "no more fuel no more reaction" scenario i introduced a if:
ReactionRate(2*ovr) = ReactionK(2)*C(4)* 1e6 /CatalystDensity; % kmol/kgcat/h
if y(ovr) < 0
ReactionRate(2*ovr) = 0; % kmol/kgcat/h
end
dydt(i) = NetRateProduction(i)*(1-VoidFraction)*CatalystDensity*mw(i)/G;
in this way the dydt=0 and the value after reaching 0 (or a small negligible negative value) should stay constant, but after integration i still see a trend that goes way past 0
-0.0978571895684889
-0.0978554762967198
-0.0978537439506636
-0.0978519924638089
since the Ode for this specie depends only on the ReactionRate if dydt+0 it should stay constant, or is an error due to the fact that to evaluate if the rate should be 0 or not i use y? i tried with the last value of y using the persistent variable
persistent y_prev
.
if y_prev(ovr) < 0
ReactionRate(2*ovr) = 0; % kmol/kgcat/h
end
%after the system of ODE
y_prev(ovr) = y(ovr)
how this happens? i tested with de-bugging to see if the Ode=0 if the condition on y is satisfied and eas zero, so a constant behaviour, but in the results the diminishing trend is still present.
Thank you so much for your helpHello everyone,
I’m imprementing an adjustment to my chemical reactor design regarding physical limitation, due to the kinetics the value of one specie goes negative (comuptationally correct, but not physically) to account for the "no more fuel no more reaction" scenario i introduced a if:
ReactionRate(2*ovr) = ReactionK(2)*C(4)* 1e6 /CatalystDensity; % kmol/kgcat/h
if y(ovr) < 0
ReactionRate(2*ovr) = 0; % kmol/kgcat/h
end
dydt(i) = NetRateProduction(i)*(1-VoidFraction)*CatalystDensity*mw(i)/G;
in this way the dydt=0 and the value after reaching 0 (or a small negligible negative value) should stay constant, but after integration i still see a trend that goes way past 0
-0.0978571895684889
-0.0978554762967198
-0.0978537439506636
-0.0978519924638089
since the Ode for this specie depends only on the ReactionRate if dydt+0 it should stay constant, or is an error due to the fact that to evaluate if the rate should be 0 or not i use y? i tried with the last value of y using the persistent variable
persistent y_prev
.
if y_prev(ovr) < 0
ReactionRate(2*ovr) = 0; % kmol/kgcat/h
end
%after the system of ODE
y_prev(ovr) = y(ovr)
how this happens? i tested with de-bugging to see if the Ode=0 if the condition on y is satisfied and eas zero, so a constant behaviour, but in the results the diminishing trend is still present.
Thank you so much for your help Hello everyone,
I’m imprementing an adjustment to my chemical reactor design regarding physical limitation, due to the kinetics the value of one specie goes negative (comuptationally correct, but not physically) to account for the "no more fuel no more reaction" scenario i introduced a if:
ReactionRate(2*ovr) = ReactionK(2)*C(4)* 1e6 /CatalystDensity; % kmol/kgcat/h
if y(ovr) < 0
ReactionRate(2*ovr) = 0; % kmol/kgcat/h
end
dydt(i) = NetRateProduction(i)*(1-VoidFraction)*CatalystDensity*mw(i)/G;
in this way the dydt=0 and the value after reaching 0 (or a small negligible negative value) should stay constant, but after integration i still see a trend that goes way past 0
-0.0978571895684889
-0.0978554762967198
-0.0978537439506636
-0.0978519924638089
since the Ode for this specie depends only on the ReactionRate if dydt+0 it should stay constant, or is an error due to the fact that to evaluate if the rate should be 0 or not i use y? i tried with the last value of y using the persistent variable
persistent y_prev
.
if y_prev(ovr) < 0
ReactionRate(2*ovr) = 0; % kmol/kgcat/h
end
%after the system of ODE
y_prev(ovr) = y(ovr)
how this happens? i tested with de-bugging to see if the Ode=0 if the condition on y is satisfied and eas zero, so a constant behaviour, but in the results the diminishing trend is still present.
Thank you so much for your help ode, if statement MATLAB Answers — New Questions
Histogram with normal distribution curve
Hello,
I have the data x and want to plot it in a histogram with the number of observations on the y-axis. I want to show also the normal distributon curve overlaying the histogram. I define V = 0:0.25:7 to the define the edges of the bins. I would like to create several histogram of different data sets with the same bin edges.
Using "hisfit" you cannot define a vector for the bin_edges only the number of bins.
Code
x = data1;
V = [0:0.25:7];
figure(1)
hisfit(x, 20, ‘normal’)
Using "histogram" you can define the edges but when I want to show the normal distribtuion curve I only manage to show it with the probability density.
Code
x = data1;
V = [0:0.25:7];
mu = mean(x);
sig = std(x);
x_normalized = linspace(min(V), max(V));
y_normalized = normpdf(x_normalized, mu, sig);
figure(1)
histogram(x, V, ‘Normalization’, ‘pdf’)
hold on;
plot(x_normalized, y_normalized, ‘r’, ‘LineWidth’, 2);
Is there a possibility to plot the data in a histogram with the normal distribtuion curve with a define bin_width and number of observations on the y-axis?
ThanksHello,
I have the data x and want to plot it in a histogram with the number of observations on the y-axis. I want to show also the normal distributon curve overlaying the histogram. I define V = 0:0.25:7 to the define the edges of the bins. I would like to create several histogram of different data sets with the same bin edges.
Using "hisfit" you cannot define a vector for the bin_edges only the number of bins.
Code
x = data1;
V = [0:0.25:7];
figure(1)
hisfit(x, 20, ‘normal’)
Using "histogram" you can define the edges but when I want to show the normal distribtuion curve I only manage to show it with the probability density.
Code
x = data1;
V = [0:0.25:7];
mu = mean(x);
sig = std(x);
x_normalized = linspace(min(V), max(V));
y_normalized = normpdf(x_normalized, mu, sig);
figure(1)
histogram(x, V, ‘Normalization’, ‘pdf’)
hold on;
plot(x_normalized, y_normalized, ‘r’, ‘LineWidth’, 2);
Is there a possibility to plot the data in a histogram with the normal distribtuion curve with a define bin_width and number of observations on the y-axis?
Thanks Hello,
I have the data x and want to plot it in a histogram with the number of observations on the y-axis. I want to show also the normal distributon curve overlaying the histogram. I define V = 0:0.25:7 to the define the edges of the bins. I would like to create several histogram of different data sets with the same bin edges.
Using "hisfit" you cannot define a vector for the bin_edges only the number of bins.
Code
x = data1;
V = [0:0.25:7];
figure(1)
hisfit(x, 20, ‘normal’)
Using "histogram" you can define the edges but when I want to show the normal distribtuion curve I only manage to show it with the probability density.
Code
x = data1;
V = [0:0.25:7];
mu = mean(x);
sig = std(x);
x_normalized = linspace(min(V), max(V));
y_normalized = normpdf(x_normalized, mu, sig);
figure(1)
histogram(x, V, ‘Normalization’, ‘pdf’)
hold on;
plot(x_normalized, y_normalized, ‘r’, ‘LineWidth’, 2);
Is there a possibility to plot the data in a histogram with the normal distribtuion curve with a define bin_width and number of observations on the y-axis?
Thanks histogram, histfit MATLAB Answers — New Questions
Howto build VNC and Browser mode into matlab docker container?
Ich cannot use the prebuilt matlab docker container as I need to provide my username to our license server. Is there any way to force the pre-built container to use a specific user name for license checkout?
When I rebuild a container using the provided Dockerfile from matlab-dockerfile to incorporate my username I am unable to use -vnc or -browser. Which packages do I have to include to get these features included? I could not find this documented anywhere. Is the Dockerfile that was used for building the prebuilt container available somewhere?
Thanks for your support.Ich cannot use the prebuilt matlab docker container as I need to provide my username to our license server. Is there any way to force the pre-built container to use a specific user name for license checkout?
When I rebuild a container using the provided Dockerfile from matlab-dockerfile to incorporate my username I am unable to use -vnc or -browser. Which packages do I have to include to get these features included? I could not find this documented anywhere. Is the Dockerfile that was used for building the prebuilt container available somewhere?
Thanks for your support. Ich cannot use the prebuilt matlab docker container as I need to provide my username to our license server. Is there any way to force the pre-built container to use a specific user name for license checkout?
When I rebuild a container using the provided Dockerfile from matlab-dockerfile to incorporate my username I am unable to use -vnc or -browser. Which packages do I have to include to get these features included? I could not find this documented anywhere. Is the Dockerfile that was used for building the prebuilt container available somewhere?
Thanks for your support. docker, container, dockerfile MATLAB Answers — New Questions
How to make a curve fill the whole plotspace
Vb0_vec = [10 1000];
mb_vec = (20*10^-3)*(36*pi*Vb0_vec.^2).^(1/3);
rhog0 = 0.169;
lambda = 0.0173;
y = linspace(0, 120000, 50000);
% plot 3: beperkende factor voor capaciteit
W_10 = Capaciteit(y, Vb0_vec(1), lambda, mb_vec(1), rhog0);
W_1000 = Capaciteit(y, Vb0_vec(2), lambda, mb_vec(2), rhog0);
figure(3)
loglog(y, W_10)
hold on
loglog(y, W_1000)
hold off
The output looks like this:
How can i make the curves cover the whole plot (touching both axes)?Vb0_vec = [10 1000];
mb_vec = (20*10^-3)*(36*pi*Vb0_vec.^2).^(1/3);
rhog0 = 0.169;
lambda = 0.0173;
y = linspace(0, 120000, 50000);
% plot 3: beperkende factor voor capaciteit
W_10 = Capaciteit(y, Vb0_vec(1), lambda, mb_vec(1), rhog0);
W_1000 = Capaciteit(y, Vb0_vec(2), lambda, mb_vec(2), rhog0);
figure(3)
loglog(y, W_10)
hold on
loglog(y, W_1000)
hold off
The output looks like this:
How can i make the curves cover the whole plot (touching both axes)? Vb0_vec = [10 1000];
mb_vec = (20*10^-3)*(36*pi*Vb0_vec.^2).^(1/3);
rhog0 = 0.169;
lambda = 0.0173;
y = linspace(0, 120000, 50000);
% plot 3: beperkende factor voor capaciteit
W_10 = Capaciteit(y, Vb0_vec(1), lambda, mb_vec(1), rhog0);
W_1000 = Capaciteit(y, Vb0_vec(2), lambda, mb_vec(2), rhog0);
figure(3)
loglog(y, W_10)
hold on
loglog(y, W_1000)
hold off
The output looks like this:
How can i make the curves cover the whole plot (touching both axes)? filling plot MATLAB Answers — New Questions
Microsoft senior leadership update: EVP, Chief People Officer and EVP, Office of Strategy and Transformation
Satya Nadella, Chairman and CEO, shared the below communication with Microsoft employees this morning.
As we’ve seen time and again throughout our 50-year history, times of great change for the world and for our industry require us to have a mindset that enables us to continually adapt and transform ourselves. There’s no question that we are at the forefront of another such moment, with the rapid changes across every industry and business function in this AI era.
This means we must have the right product portfolio, the right business models, attract and retain top talent, and optimize our processes to meet changing customer expectations and succeed in the marketplace.
With this context, I’ve asked Kathleen Hogan to transition to a new role focused on defining our overarching corporate strategy and structure and leading our continuous transformation as a company. Kathleen will assume a new role as EVP, Office of Strategy and Transformation, reporting to me.
It is hard to overstate the impact Kathleen has had on Microsoft as Chief People Officer. Over the past 10+ years, she has led our cultural transformation, as we embraced a growth mindset, positioning us to seize new opportunities with agility and attract and retain world-class talent. She is recognized externally as a consequential HR leader transforming culture and the world of work. Her more than 20-year tenure at Microsoft, including leading our global services business, paired with her prior experience as a McKinsey partner in Silicon Valley, and a development manager at Oracle, makes her uniquely suited to lead this work as we accelerate our pace of change across our people, processes, and portfolio. Kathleen will work across the SLT as we chart this next phase of our transformation, which requires both interpreting the outside and redefining the inside.
Kathleen and I have been discussing this transition and succession planning for some time, and we both agree this is the critical juncture to apply new focus and intention to this work.
With this transition, I’m very pleased to share that Amy Coleman will assume the role of EVP, Chief People Officer, leading our HR organization. She joins the senior leadership team reporting to me.
Amy has led HR for our corporate functions across the company for the past six years, following various HR roles partnering across engineering, sales, marketing, and business development spanning 25 years. In that time, she has been a trusted advisor to both Kathleen and to me as she orchestrated many cross-company workstreams as we evolved our culture, improved our employee engagement model, established our employee relations team, and drove enterprise crisis response for our people. Amy’s commitment to operational excellence and high performance will be key in driving our continued success, and I’m confident in the perspective, expertise, and thoughtful approach she’ll bring as we navigate the next phase of our journey.
Please join me in congratulating Kathleen and Amy on their new roles.
Satya
The post Microsoft senior leadership update: EVP, Chief People Officer and EVP, Office of Strategy and Transformation appeared first on The Official Microsoft Blog.
Satya Nadella, Chairman and CEO, shared the below communication with Microsoft employees this morning. As we’ve seen time and again throughout our 50-year history, times of great change for the world and for our industry require us to have a mindset that enables us to continually adapt and transform ourselves. There’s no question that we…
The post Microsoft senior leadership update: EVP, Chief People Officer and EVP, Office of Strategy and Transformation appeared first on The Official Microsoft Blog.Read More
How to split a table into multiple tables based on value in a column?
Hello,
I am reading in an excel file that has 2 columns of data. One of them has a lot number and the other has row/col numbers.
I’ve made a table that holds this information, however, I would like to make multiple tables for every set of lot numbers.
I’ve attached an example excel sheet. In this example there are 2 different lot numbers, so I would need it to make 2 different tables for each lot number with each corresponding row, col number! I also need it to be able to adjust if there are more than 2 different lot numbers because the sheet is always updated.
Thanks!Hello,
I am reading in an excel file that has 2 columns of data. One of them has a lot number and the other has row/col numbers.
I’ve made a table that holds this information, however, I would like to make multiple tables for every set of lot numbers.
I’ve attached an example excel sheet. In this example there are 2 different lot numbers, so I would need it to make 2 different tables for each lot number with each corresponding row, col number! I also need it to be able to adjust if there are more than 2 different lot numbers because the sheet is always updated.
Thanks! Hello,
I am reading in an excel file that has 2 columns of data. One of them has a lot number and the other has row/col numbers.
I’ve made a table that holds this information, however, I would like to make multiple tables for every set of lot numbers.
I’ve attached an example excel sheet. In this example there are 2 different lot numbers, so I would need it to make 2 different tables for each lot number with each corresponding row, col number! I also need it to be able to adjust if there are more than 2 different lot numbers because the sheet is always updated.
Thanks! matlab, excel MATLAB Answers — New Questions
any option as applying while code to develop pipeline connection within looped network; has noted zero indexing
Post Content Post Content thingspeak MATLAB Answers — New Questions