Category: Matlab
Category Archives: Matlab
Using MATLAB to do Numeric Calculus
So I am culminating all of my newfound knowledge to solve and show a simple calculus problem. However I am running into issues…
Given: A piecewise function where v(t)=70t @ t<=20s & 1596.2-9.81t @ 20<t<t_max <—(eq 1)
Also given: s(t)=35t^2+7620 @ t<=20s & 1596.2t-4.905t^2-8342 @ 20<t<=t_max <—(eq 2)
Find: If aircraft ignites its engines at t=0s and accelerates vertically, there is only enough fuel for an engine burn of 20 seconds. At which time will the ship become a projectile? Find value of t_max. Plot the crafts velocity vs. t, (eq 1). Plot the crafts altitude vs. t, (eq 2).
My Solution:
%% Finding Value of tmax
% Finding tmax and rounding it to the nearest whole number
%%
tmaxr=roots([-9.81, 1596.2]);
tmax=ceil(tmaxr);
%% Plotting Equation 1
% Creating Figure 1 from Equation 1
%%
t=0:0.1:tmax;
v=zeros(size(t));
for N=1:length(t)
if t(N)<=20
v(N)=70*t(N);
else
v(N)=1596.2-9.81*t(N); % Only valid for t > 20 seconds
end
end
figure(1)
plot(t,v)
xlabel(‘Time (s)’)
ylabel(‘Velocity (m/s)’)
title(‘Velocity vs. Time’)
%% Plotting Equation 2
% Creating Figure 2 from Equation 2
%%
t=0:0.1:tmax;
s=zeros(size(t));
for N=1:length(t)
if t(N)<=20
s(N)=35.*t(N).^2+7620;
else
s(N)=1596.2.*t(N)-4.905.*t(N).^2-8342;
end
end
figure(2)
plot(t,s)
xlabel(‘Time (s)’)
ylabel(‘Altitude (m)’)
title(‘Position vs. Time’)
Issue: So I have found t_max, plotted the velocity but it looks funky, and also tried to plot my altitide but not sure if it’s faultless.
P.s. Sorry for the formatting, there’s no easy way to type piecewise functions that I know of.So I am culminating all of my newfound knowledge to solve and show a simple calculus problem. However I am running into issues…
Given: A piecewise function where v(t)=70t @ t<=20s & 1596.2-9.81t @ 20<t<t_max <—(eq 1)
Also given: s(t)=35t^2+7620 @ t<=20s & 1596.2t-4.905t^2-8342 @ 20<t<=t_max <—(eq 2)
Find: If aircraft ignites its engines at t=0s and accelerates vertically, there is only enough fuel for an engine burn of 20 seconds. At which time will the ship become a projectile? Find value of t_max. Plot the crafts velocity vs. t, (eq 1). Plot the crafts altitude vs. t, (eq 2).
My Solution:
%% Finding Value of tmax
% Finding tmax and rounding it to the nearest whole number
%%
tmaxr=roots([-9.81, 1596.2]);
tmax=ceil(tmaxr);
%% Plotting Equation 1
% Creating Figure 1 from Equation 1
%%
t=0:0.1:tmax;
v=zeros(size(t));
for N=1:length(t)
if t(N)<=20
v(N)=70*t(N);
else
v(N)=1596.2-9.81*t(N); % Only valid for t > 20 seconds
end
end
figure(1)
plot(t,v)
xlabel(‘Time (s)’)
ylabel(‘Velocity (m/s)’)
title(‘Velocity vs. Time’)
%% Plotting Equation 2
% Creating Figure 2 from Equation 2
%%
t=0:0.1:tmax;
s=zeros(size(t));
for N=1:length(t)
if t(N)<=20
s(N)=35.*t(N).^2+7620;
else
s(N)=1596.2.*t(N)-4.905.*t(N).^2-8342;
end
end
figure(2)
plot(t,s)
xlabel(‘Time (s)’)
ylabel(‘Altitude (m)’)
title(‘Position vs. Time’)
Issue: So I have found t_max, plotted the velocity but it looks funky, and also tried to plot my altitide but not sure if it’s faultless.
P.s. Sorry for the formatting, there’s no easy way to type piecewise functions that I know of. So I am culminating all of my newfound knowledge to solve and show a simple calculus problem. However I am running into issues…
Given: A piecewise function where v(t)=70t @ t<=20s & 1596.2-9.81t @ 20<t<t_max <—(eq 1)
Also given: s(t)=35t^2+7620 @ t<=20s & 1596.2t-4.905t^2-8342 @ 20<t<=t_max <—(eq 2)
Find: If aircraft ignites its engines at t=0s and accelerates vertically, there is only enough fuel for an engine burn of 20 seconds. At which time will the ship become a projectile? Find value of t_max. Plot the crafts velocity vs. t, (eq 1). Plot the crafts altitude vs. t, (eq 2).
My Solution:
%% Finding Value of tmax
% Finding tmax and rounding it to the nearest whole number
%%
tmaxr=roots([-9.81, 1596.2]);
tmax=ceil(tmaxr);
%% Plotting Equation 1
% Creating Figure 1 from Equation 1
%%
t=0:0.1:tmax;
v=zeros(size(t));
for N=1:length(t)
if t(N)<=20
v(N)=70*t(N);
else
v(N)=1596.2-9.81*t(N); % Only valid for t > 20 seconds
end
end
figure(1)
plot(t,v)
xlabel(‘Time (s)’)
ylabel(‘Velocity (m/s)’)
title(‘Velocity vs. Time’)
%% Plotting Equation 2
% Creating Figure 2 from Equation 2
%%
t=0:0.1:tmax;
s=zeros(size(t));
for N=1:length(t)
if t(N)<=20
s(N)=35.*t(N).^2+7620;
else
s(N)=1596.2.*t(N)-4.905.*t(N).^2-8342;
end
end
figure(2)
plot(t,s)
xlabel(‘Time (s)’)
ylabel(‘Altitude (m)’)
title(‘Position vs. Time’)
Issue: So I have found t_max, plotted the velocity but it looks funky, and also tried to plot my altitide but not sure if it’s faultless.
P.s. Sorry for the formatting, there’s no easy way to type piecewise functions that I know of. calculus, plotting MATLAB Answers — New Questions
Installation of MATLAB in Linux failed
I installed MATLAB at a Linux Debian system, but a problem occurs while starting the programme. I’ll get a graphical interface, but in the terminal the following is displayed:
MATLAB is selecting SOFTWARE OPENGL rendering.
/usr/local/MATLAB/R2017b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `CXXABI_1.3.9′ not found (required by /usr/lib/x86_64-linux-gnu/libproxy.so.1)
Failed to load module: /usr/lib/x86_64-linux-gnu/gio/modules/libgiolibproxy.soI installed MATLAB at a Linux Debian system, but a problem occurs while starting the programme. I’ll get a graphical interface, but in the terminal the following is displayed:
MATLAB is selecting SOFTWARE OPENGL rendering.
/usr/local/MATLAB/R2017b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `CXXABI_1.3.9′ not found (required by /usr/lib/x86_64-linux-gnu/libproxy.so.1)
Failed to load module: /usr/lib/x86_64-linux-gnu/gio/modules/libgiolibproxy.so I installed MATLAB at a Linux Debian system, but a problem occurs while starting the programme. I’ll get a graphical interface, but in the terminal the following is displayed:
MATLAB is selecting SOFTWARE OPENGL rendering.
/usr/local/MATLAB/R2017b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `CXXABI_1.3.9′ not found (required by /usr/lib/x86_64-linux-gnu/libproxy.so.1)
Failed to load module: /usr/lib/x86_64-linux-gnu/gio/modules/libgiolibproxy.so linux installation matlab MATLAB Answers — New Questions
I want to increase the distance, the dimensions of the viewing screen should be such that all the beams are on the screen while the pixel value is fixed.
Hi
Look at this code:
close all; clear; clc
N = 2560;
L = 1e4;
dx = 4e-3;
[x0,y0] = meshgrid((-N/2:N/2-1)*dx);
[xL,yL] = meshgrid((-N/2:N/2-1)*dx);
[fx,fy] = meshgrid((-N/2:N/2-1)/(N*dx));
Ni = 37; % Number of beams
d= 25e-2;
a= pi./3;
xi= [ 0 , – d , – d.*cos(a) ,d.*cos(a),d ,d.*cos(a), -d.*cos(a)…
,-2.*d , -2.*d.*cos(a), 0,2.*d.*cos(a), 2.*d, 2.*d.*cos(a),0 , -2.*d.*cos(a)…
, -d-d.*cos(a), d+d.*cos(a), d+d.*cos(a) , -d-d.*cos(a)…
, 3.*d.*cos(a),3.*d.*cos(a)-d, -3.*d.*cos(a)+d , -3.*d.*cos(a), 2.*d.*cos(a)+d,3.*d.*cos(a)+d…
3.*d,3.*d.*cos(a)+d, 2.*d.*cos(a)+d, 3.*d.*cos(a),3.*d.*cos(a)-d, -3.*d.*cos(a)+d , -3.*d.*cos(a)…
,-2.*d.*cos(a)-d ,-3.*d.*cos(a)-d , – 3.*d ,-2.*d.*cos(a)-d ,-3.*d.*cos(a)-d] ;
yi= [ 0 , 0 , d.*sin(a),d.*sin(a), 0 , -d.*sin(a), -d.*sin(a)…
,0 , 2.*d.*sin(a), 2.*d.*sin(a),2.*d.*sin(a), 0 , – 2.*d.*sin(a), -2.*d.*sin(a)…
, – 2.*d.*sin(a), d.*sin(a),d.*sin(a), -d.*sin(a),-d.*sin(a)…
, 3.*d.*sin(a),3.*d.*sin(a),3.*d.*sin(a),3.*d.*sin(a), 2.*d.*sin(a),d.*sin(a), 0 …
, -d.*sin(a), -2.*d.*sin(a), -3.*d.*sin(a), -3.*d.*sin(a), -3.*d.*sin(a),-3.*d.*sin(a)…
,2.*d.*sin(a), d.*sin(a), 0 , -2.*d.*sin(a), -d.*sin(a)];
w0 = 10e-2;
P = 1e3;
lambda = 1080e-9; k = 2*pi/lambda;
L0= 10; l0= 5e-3;
kL= 2.*pi./L0; kl= 5.92./l0;
Cn2= randi([1 1000],1,60)*1e-16;
Kx = 2.*pi.*fx; Ky = 2.*pi.*fy;
U0= 0*x0;
for idx=1:Ni
Utemp = U0 + sqrt(2.*P./pi)./w0 .* exp(-((x0-xi(idx)).^2+(y0-yi(idx)).^2)./w0.^2);
Utemp(((x0-xi(idx)).^2+(y0-yi(idx)).^2)>w0.^2) = 0;
U0= U0 + Utemp;
end
Ui=U0;
figure(1000)
s = pcolor(x0, y0, abs(Ui));
s.EdgeColor = ‘none’;
title("0^{th} Intenesity screen")
xlabel ‘X [m] ‘
ylabel ‘Y [m] ‘
cbar = colorbar;
cbar.Label.String = ‘Intensity(X, Y, 0) [W/cm^2]’;
ax = gca;
axis square
ax.FontName = ‘Times new roman’;
ax.FontSize = 15;
Ni=60; % Number of page views
for idx = 1:Ni
r0= (0.423 .* k.^2 .* Cn2(idx).*L )^(-3/5);
phi = 0.023*r0.^2^(-3./5)*exp(-((Kx^2 + Ky^2) ./ kl.^2)) .* ((Kx.^2 + Ky.^2 + kL^2) ./ (4*pi^2)).^(-11./6);
sigma= 1./(N*dx).*sqrt(phi);
c = randn(N) + i*randn(N);
random_sigma= c.* sigma;
random_sigma(N./2+1,N./2+1)=0;
phi_xy = real(ifftshift(ifft2(ifftshift(random_sigma)))) / dx^2;
Hf = exp(i*k*L).* exp(-i*pi*lambda*L*(fx.^2+fy.^2));
G = fftshift(fft2(fftshift(Ui))) * dx^2;
Ui = ifftshift(ifft2(ifftshift(G.*Hf))) / dx^2;
Ui = Ui .* exp(1i*phi_xy);
figure(2*idx-1)
s = pcolor(x0, y0, phi_xy);
s.EdgeColor = ‘none’;
title(num2str(idx)+"^{th} phase screen")
xlabel ‘X [m]’
ylabel ‘Y [m]’
cbar = colorbar;
cbar.Label.String = ‘Intensity(X, Y, 0) [W/cm^2]’;
ax = gca;
axis square
ax.FontName = ‘Times new roman’;
ax.FontSize = 15;
figure(2*idx)
s = pcolor(xL, yL, abs(Ui));
title(num2str(idx)+"^{th} Intenesity screen")
s.EdgeColor = ‘none’;
xlabel ‘X [m] ‘
ylabel ‘Y [m] ‘
cbar = colorbar;
cbar.Label.String = ‘Intensity(X, Y, 0) [W/cm^2]’;
ax = gca;
axis square
ax.FontName = ‘Times new roman’;
ax.FontSize = 15;
end
In order to see the result at any desired distance (in this code up to L = 1e 4), I have to change the number of pixels (N) according to the desired distance so that all the beams are on the viewing screen.
Now I want the code to be in such a way that by increasing the distance and keeping the number of pixels (512) constant, the dimensions of the viewing screen can accommodate all the beams.Hi
Look at this code:
close all; clear; clc
N = 2560;
L = 1e4;
dx = 4e-3;
[x0,y0] = meshgrid((-N/2:N/2-1)*dx);
[xL,yL] = meshgrid((-N/2:N/2-1)*dx);
[fx,fy] = meshgrid((-N/2:N/2-1)/(N*dx));
Ni = 37; % Number of beams
d= 25e-2;
a= pi./3;
xi= [ 0 , – d , – d.*cos(a) ,d.*cos(a),d ,d.*cos(a), -d.*cos(a)…
,-2.*d , -2.*d.*cos(a), 0,2.*d.*cos(a), 2.*d, 2.*d.*cos(a),0 , -2.*d.*cos(a)…
, -d-d.*cos(a), d+d.*cos(a), d+d.*cos(a) , -d-d.*cos(a)…
, 3.*d.*cos(a),3.*d.*cos(a)-d, -3.*d.*cos(a)+d , -3.*d.*cos(a), 2.*d.*cos(a)+d,3.*d.*cos(a)+d…
3.*d,3.*d.*cos(a)+d, 2.*d.*cos(a)+d, 3.*d.*cos(a),3.*d.*cos(a)-d, -3.*d.*cos(a)+d , -3.*d.*cos(a)…
,-2.*d.*cos(a)-d ,-3.*d.*cos(a)-d , – 3.*d ,-2.*d.*cos(a)-d ,-3.*d.*cos(a)-d] ;
yi= [ 0 , 0 , d.*sin(a),d.*sin(a), 0 , -d.*sin(a), -d.*sin(a)…
,0 , 2.*d.*sin(a), 2.*d.*sin(a),2.*d.*sin(a), 0 , – 2.*d.*sin(a), -2.*d.*sin(a)…
, – 2.*d.*sin(a), d.*sin(a),d.*sin(a), -d.*sin(a),-d.*sin(a)…
, 3.*d.*sin(a),3.*d.*sin(a),3.*d.*sin(a),3.*d.*sin(a), 2.*d.*sin(a),d.*sin(a), 0 …
, -d.*sin(a), -2.*d.*sin(a), -3.*d.*sin(a), -3.*d.*sin(a), -3.*d.*sin(a),-3.*d.*sin(a)…
,2.*d.*sin(a), d.*sin(a), 0 , -2.*d.*sin(a), -d.*sin(a)];
w0 = 10e-2;
P = 1e3;
lambda = 1080e-9; k = 2*pi/lambda;
L0= 10; l0= 5e-3;
kL= 2.*pi./L0; kl= 5.92./l0;
Cn2= randi([1 1000],1,60)*1e-16;
Kx = 2.*pi.*fx; Ky = 2.*pi.*fy;
U0= 0*x0;
for idx=1:Ni
Utemp = U0 + sqrt(2.*P./pi)./w0 .* exp(-((x0-xi(idx)).^2+(y0-yi(idx)).^2)./w0.^2);
Utemp(((x0-xi(idx)).^2+(y0-yi(idx)).^2)>w0.^2) = 0;
U0= U0 + Utemp;
end
Ui=U0;
figure(1000)
s = pcolor(x0, y0, abs(Ui));
s.EdgeColor = ‘none’;
title("0^{th} Intenesity screen")
xlabel ‘X [m] ‘
ylabel ‘Y [m] ‘
cbar = colorbar;
cbar.Label.String = ‘Intensity(X, Y, 0) [W/cm^2]’;
ax = gca;
axis square
ax.FontName = ‘Times new roman’;
ax.FontSize = 15;
Ni=60; % Number of page views
for idx = 1:Ni
r0= (0.423 .* k.^2 .* Cn2(idx).*L )^(-3/5);
phi = 0.023*r0.^2^(-3./5)*exp(-((Kx^2 + Ky^2) ./ kl.^2)) .* ((Kx.^2 + Ky.^2 + kL^2) ./ (4*pi^2)).^(-11./6);
sigma= 1./(N*dx).*sqrt(phi);
c = randn(N) + i*randn(N);
random_sigma= c.* sigma;
random_sigma(N./2+1,N./2+1)=0;
phi_xy = real(ifftshift(ifft2(ifftshift(random_sigma)))) / dx^2;
Hf = exp(i*k*L).* exp(-i*pi*lambda*L*(fx.^2+fy.^2));
G = fftshift(fft2(fftshift(Ui))) * dx^2;
Ui = ifftshift(ifft2(ifftshift(G.*Hf))) / dx^2;
Ui = Ui .* exp(1i*phi_xy);
figure(2*idx-1)
s = pcolor(x0, y0, phi_xy);
s.EdgeColor = ‘none’;
title(num2str(idx)+"^{th} phase screen")
xlabel ‘X [m]’
ylabel ‘Y [m]’
cbar = colorbar;
cbar.Label.String = ‘Intensity(X, Y, 0) [W/cm^2]’;
ax = gca;
axis square
ax.FontName = ‘Times new roman’;
ax.FontSize = 15;
figure(2*idx)
s = pcolor(xL, yL, abs(Ui));
title(num2str(idx)+"^{th} Intenesity screen")
s.EdgeColor = ‘none’;
xlabel ‘X [m] ‘
ylabel ‘Y [m] ‘
cbar = colorbar;
cbar.Label.String = ‘Intensity(X, Y, 0) [W/cm^2]’;
ax = gca;
axis square
ax.FontName = ‘Times new roman’;
ax.FontSize = 15;
end
In order to see the result at any desired distance (in this code up to L = 1e 4), I have to change the number of pixels (N) according to the desired distance so that all the beams are on the viewing screen.
Now I want the code to be in such a way that by increasing the distance and keeping the number of pixels (512) constant, the dimensions of the viewing screen can accommodate all the beams. Hi
Look at this code:
close all; clear; clc
N = 2560;
L = 1e4;
dx = 4e-3;
[x0,y0] = meshgrid((-N/2:N/2-1)*dx);
[xL,yL] = meshgrid((-N/2:N/2-1)*dx);
[fx,fy] = meshgrid((-N/2:N/2-1)/(N*dx));
Ni = 37; % Number of beams
d= 25e-2;
a= pi./3;
xi= [ 0 , – d , – d.*cos(a) ,d.*cos(a),d ,d.*cos(a), -d.*cos(a)…
,-2.*d , -2.*d.*cos(a), 0,2.*d.*cos(a), 2.*d, 2.*d.*cos(a),0 , -2.*d.*cos(a)…
, -d-d.*cos(a), d+d.*cos(a), d+d.*cos(a) , -d-d.*cos(a)…
, 3.*d.*cos(a),3.*d.*cos(a)-d, -3.*d.*cos(a)+d , -3.*d.*cos(a), 2.*d.*cos(a)+d,3.*d.*cos(a)+d…
3.*d,3.*d.*cos(a)+d, 2.*d.*cos(a)+d, 3.*d.*cos(a),3.*d.*cos(a)-d, -3.*d.*cos(a)+d , -3.*d.*cos(a)…
,-2.*d.*cos(a)-d ,-3.*d.*cos(a)-d , – 3.*d ,-2.*d.*cos(a)-d ,-3.*d.*cos(a)-d] ;
yi= [ 0 , 0 , d.*sin(a),d.*sin(a), 0 , -d.*sin(a), -d.*sin(a)…
,0 , 2.*d.*sin(a), 2.*d.*sin(a),2.*d.*sin(a), 0 , – 2.*d.*sin(a), -2.*d.*sin(a)…
, – 2.*d.*sin(a), d.*sin(a),d.*sin(a), -d.*sin(a),-d.*sin(a)…
, 3.*d.*sin(a),3.*d.*sin(a),3.*d.*sin(a),3.*d.*sin(a), 2.*d.*sin(a),d.*sin(a), 0 …
, -d.*sin(a), -2.*d.*sin(a), -3.*d.*sin(a), -3.*d.*sin(a), -3.*d.*sin(a),-3.*d.*sin(a)…
,2.*d.*sin(a), d.*sin(a), 0 , -2.*d.*sin(a), -d.*sin(a)];
w0 = 10e-2;
P = 1e3;
lambda = 1080e-9; k = 2*pi/lambda;
L0= 10; l0= 5e-3;
kL= 2.*pi./L0; kl= 5.92./l0;
Cn2= randi([1 1000],1,60)*1e-16;
Kx = 2.*pi.*fx; Ky = 2.*pi.*fy;
U0= 0*x0;
for idx=1:Ni
Utemp = U0 + sqrt(2.*P./pi)./w0 .* exp(-((x0-xi(idx)).^2+(y0-yi(idx)).^2)./w0.^2);
Utemp(((x0-xi(idx)).^2+(y0-yi(idx)).^2)>w0.^2) = 0;
U0= U0 + Utemp;
end
Ui=U0;
figure(1000)
s = pcolor(x0, y0, abs(Ui));
s.EdgeColor = ‘none’;
title("0^{th} Intenesity screen")
xlabel ‘X [m] ‘
ylabel ‘Y [m] ‘
cbar = colorbar;
cbar.Label.String = ‘Intensity(X, Y, 0) [W/cm^2]’;
ax = gca;
axis square
ax.FontName = ‘Times new roman’;
ax.FontSize = 15;
Ni=60; % Number of page views
for idx = 1:Ni
r0= (0.423 .* k.^2 .* Cn2(idx).*L )^(-3/5);
phi = 0.023*r0.^2^(-3./5)*exp(-((Kx^2 + Ky^2) ./ kl.^2)) .* ((Kx.^2 + Ky.^2 + kL^2) ./ (4*pi^2)).^(-11./6);
sigma= 1./(N*dx).*sqrt(phi);
c = randn(N) + i*randn(N);
random_sigma= c.* sigma;
random_sigma(N./2+1,N./2+1)=0;
phi_xy = real(ifftshift(ifft2(ifftshift(random_sigma)))) / dx^2;
Hf = exp(i*k*L).* exp(-i*pi*lambda*L*(fx.^2+fy.^2));
G = fftshift(fft2(fftshift(Ui))) * dx^2;
Ui = ifftshift(ifft2(ifftshift(G.*Hf))) / dx^2;
Ui = Ui .* exp(1i*phi_xy);
figure(2*idx-1)
s = pcolor(x0, y0, phi_xy);
s.EdgeColor = ‘none’;
title(num2str(idx)+"^{th} phase screen")
xlabel ‘X [m]’
ylabel ‘Y [m]’
cbar = colorbar;
cbar.Label.String = ‘Intensity(X, Y, 0) [W/cm^2]’;
ax = gca;
axis square
ax.FontName = ‘Times new roman’;
ax.FontSize = 15;
figure(2*idx)
s = pcolor(xL, yL, abs(Ui));
title(num2str(idx)+"^{th} Intenesity screen")
s.EdgeColor = ‘none’;
xlabel ‘X [m] ‘
ylabel ‘Y [m] ‘
cbar = colorbar;
cbar.Label.String = ‘Intensity(X, Y, 0) [W/cm^2]’;
ax = gca;
axis square
ax.FontName = ‘Times new roman’;
ax.FontSize = 15;
end
In order to see the result at any desired distance (in this code up to L = 1e 4), I have to change the number of pixels (N) according to the desired distance so that all the beams are on the viewing screen.
Now I want the code to be in such a way that by increasing the distance and keeping the number of pixels (512) constant, the dimensions of the viewing screen can accommodate all the beams. plot, plotting, fft MATLAB Answers — New Questions
Interpolating from one grid to another
Hello experts
Please, could someone help me with an interpolation?
I have two different 2D scattered grids (X = longitude, Y = depth), and a variable temperature, from two different datasets. On the first one x and y are 41×37, and on the second 24×10. Also Temp1 (41×37) and Temp2 (24×10).
I need to compute the difference (Temp1 – Temp2), but for that, I need Temp2 to be on the same format (and coordenates) as Temp1, that is, 41×37. Then, I guess I have to interpolate X2, Y2, Temp2, to the coordinates of X1, Y1.
I tried scatteredInterpolant function, but I it doesn’t work, moreover, it does not allow me to inform the reference coordinates, that is, X1,Y1.
Both scatteredInterpolant and TriScatteredInterp has the structure F = function(x,y,v), but I need something like NewTemp2 = function(X1,Y1,X2,Y2,Temp2).
Please, could someone help me with this?
The data is attached, thank you very much in advance!Hello experts
Please, could someone help me with an interpolation?
I have two different 2D scattered grids (X = longitude, Y = depth), and a variable temperature, from two different datasets. On the first one x and y are 41×37, and on the second 24×10. Also Temp1 (41×37) and Temp2 (24×10).
I need to compute the difference (Temp1 – Temp2), but for that, I need Temp2 to be on the same format (and coordenates) as Temp1, that is, 41×37. Then, I guess I have to interpolate X2, Y2, Temp2, to the coordinates of X1, Y1.
I tried scatteredInterpolant function, but I it doesn’t work, moreover, it does not allow me to inform the reference coordinates, that is, X1,Y1.
Both scatteredInterpolant and TriScatteredInterp has the structure F = function(x,y,v), but I need something like NewTemp2 = function(X1,Y1,X2,Y2,Temp2).
Please, could someone help me with this?
The data is attached, thank you very much in advance! Hello experts
Please, could someone help me with an interpolation?
I have two different 2D scattered grids (X = longitude, Y = depth), and a variable temperature, from two different datasets. On the first one x and y are 41×37, and on the second 24×10. Also Temp1 (41×37) and Temp2 (24×10).
I need to compute the difference (Temp1 – Temp2), but for that, I need Temp2 to be on the same format (and coordenates) as Temp1, that is, 41×37. Then, I guess I have to interpolate X2, Y2, Temp2, to the coordinates of X1, Y1.
I tried scatteredInterpolant function, but I it doesn’t work, moreover, it does not allow me to inform the reference coordinates, that is, X1,Y1.
Both scatteredInterpolant and TriScatteredInterp has the structure F = function(x,y,v), but I need something like NewTemp2 = function(X1,Y1,X2,Y2,Temp2).
Please, could someone help me with this?
The data is attached, thank you very much in advance! interpolation, grid MATLAB Answers — New Questions
Arduino Uno R4 Wifi Port Problem
Hello, everyone,
I am trying to install the Arduino hardware support package and at the step "Test Arduino Connection", Download failed is shown up (in the image). Moreover, I am getting the data from Arduino Uno R3, but when I try to get from Arduino Uno R4 Wifi, I get an error (mentioned in the same image), I don’t know why I am getting the error. However, when I first tried R3 board I was getting the same error but it got fixed and was able to get the data. With Arduino Uno R4 Wifi, I am unable to fix the problem despite simulink is detecting port very well. I request you all to help me in fixing the problem.
Error:
Thank you
ShivamHello, everyone,
I am trying to install the Arduino hardware support package and at the step "Test Arduino Connection", Download failed is shown up (in the image). Moreover, I am getting the data from Arduino Uno R3, but when I try to get from Arduino Uno R4 Wifi, I get an error (mentioned in the same image), I don’t know why I am getting the error. However, when I first tried R3 board I was getting the same error but it got fixed and was able to get the data. With Arduino Uno R4 Wifi, I am unable to fix the problem despite simulink is detecting port very well. I request you all to help me in fixing the problem.
Error:
Thank you
Shivam Hello, everyone,
I am trying to install the Arduino hardware support package and at the step "Test Arduino Connection", Download failed is shown up (in the image). Moreover, I am getting the data from Arduino Uno R3, but when I try to get from Arduino Uno R4 Wifi, I get an error (mentioned in the same image), I don’t know why I am getting the error. However, when I first tried R3 board I was getting the same error but it got fixed and was able to get the data. With Arduino Uno R4 Wifi, I am unable to fix the problem despite simulink is detecting port very well. I request you all to help me in fixing the problem.
Error:
Thank you
Shivam simulink, arduino, uno MATLAB Answers — New Questions
probability that values are belong to an interval
how do i determine the probability that 𝑥 belongs to the interval [y , z] if x is a set of data and i have values for y and zhow do i determine the probability that 𝑥 belongs to the interval [y , z] if x is a set of data and i have values for y and z how do i determine the probability that 𝑥 belongs to the interval [y , z] if x is a set of data and i have values for y and z interval MATLAB Answers — New Questions
split up a matrix at discontinuities
I have matricies of varying sizes, how can i split them where the time is discontinous? Time is in seconds with 60 seconds in between each interval, otherwise it is considered "discontinous"
Example:
Here the data set is "discontinous" between 720 and 53138, how can I split them along with their paired Y axis without having to look at where the discontinuity is and manaually creating the different matricies?I have matricies of varying sizes, how can i split them where the time is discontinous? Time is in seconds with 60 seconds in between each interval, otherwise it is considered "discontinous"
Example:
Here the data set is "discontinous" between 720 and 53138, how can I split them along with their paired Y axis without having to look at where the discontinuity is and manaually creating the different matricies? I have matricies of varying sizes, how can i split them where the time is discontinous? Time is in seconds with 60 seconds in between each interval, otherwise it is considered "discontinous"
Example:
Here the data set is "discontinous" between 720 and 53138, how can I split them along with their paired Y axis without having to look at where the discontinuity is and manaually creating the different matricies? discontinuous matrix, split matrix MATLAB Answers — New Questions
Error using fft on code
% Not sure what I am doing wrong to be getting an error with the data type
% Load data from Signal.mat file
load(‘Spec.mat’);
% Number of rows (process realizations)
num_rows = size(Spec, 1);
% Number of samples per row
num_samples = size(Spec, 2);
% Calculate the power spectral density (PSD) for each row
psd_rows = zeros(num_rows, num_samples);
for i = 1:num_rows
psd_rows(i, 🙂 = (abs(fftshift(fft(Spec(i, :)))).^2) / num_samples; <————- error here
end
% Average the PSDs of all rows
psd_average = mean(psd_rows, 1);
% Sampling frequency (assuming 40 kHz)
Fs = 40e3;
% Frequency resolution
df = Fs / num_samples;
% Frequency axis
f_axis = (-num_samples/2 : num_samples/2 – 1) * df;
% Plot individual and composite PSDs
figure;
hold on;
for i = 1:num_rows
plot(f_axis, fftshift(psd_rows(i, :)));
end
plot(f_axis, fftshift(psd_average), ‘k’, ‘LineWidth’, 2);
xlabel(‘Frequency (Hz)’);
ylabel(‘Power/Frequency’);
title(‘Power Spectral Density (PSD)’);
legend(‘Individual PSDs’, ‘Composite PSD’);% Not sure what I am doing wrong to be getting an error with the data type
% Load data from Signal.mat file
load(‘Spec.mat’);
% Number of rows (process realizations)
num_rows = size(Spec, 1);
% Number of samples per row
num_samples = size(Spec, 2);
% Calculate the power spectral density (PSD) for each row
psd_rows = zeros(num_rows, num_samples);
for i = 1:num_rows
psd_rows(i, 🙂 = (abs(fftshift(fft(Spec(i, :)))).^2) / num_samples; <————- error here
end
% Average the PSDs of all rows
psd_average = mean(psd_rows, 1);
% Sampling frequency (assuming 40 kHz)
Fs = 40e3;
% Frequency resolution
df = Fs / num_samples;
% Frequency axis
f_axis = (-num_samples/2 : num_samples/2 – 1) * df;
% Plot individual and composite PSDs
figure;
hold on;
for i = 1:num_rows
plot(f_axis, fftshift(psd_rows(i, :)));
end
plot(f_axis, fftshift(psd_average), ‘k’, ‘LineWidth’, 2);
xlabel(‘Frequency (Hz)’);
ylabel(‘Power/Frequency’);
title(‘Power Spectral Density (PSD)’);
legend(‘Individual PSDs’, ‘Composite PSD’); % Not sure what I am doing wrong to be getting an error with the data type
% Load data from Signal.mat file
load(‘Spec.mat’);
% Number of rows (process realizations)
num_rows = size(Spec, 1);
% Number of samples per row
num_samples = size(Spec, 2);
% Calculate the power spectral density (PSD) for each row
psd_rows = zeros(num_rows, num_samples);
for i = 1:num_rows
psd_rows(i, 🙂 = (abs(fftshift(fft(Spec(i, :)))).^2) / num_samples; <————- error here
end
% Average the PSDs of all rows
psd_average = mean(psd_rows, 1);
% Sampling frequency (assuming 40 kHz)
Fs = 40e3;
% Frequency resolution
df = Fs / num_samples;
% Frequency axis
f_axis = (-num_samples/2 : num_samples/2 – 1) * df;
% Plot individual and composite PSDs
figure;
hold on;
for i = 1:num_rows
plot(f_axis, fftshift(psd_rows(i, :)));
end
plot(f_axis, fftshift(psd_average), ‘k’, ‘LineWidth’, 2);
xlabel(‘Frequency (Hz)’);
ylabel(‘Power/Frequency’);
title(‘Power Spectral Density (PSD)’);
legend(‘Individual PSDs’, ‘Composite PSD’); fft MATLAB Answers — New Questions
Align various discontinous data sets into a chronological ordered matrix
I have four data sets (K,L,M,N) that look at Y-Axis over 24 hours in seconds given in 60 second time intervals ( time, elevation matrix), all with different matrix lengths from two different sections (two sets from each section (A or B))
The time in these data sets is not continuous.
I want to combine the data and align them in a chronological time vector that spans 1: 86400 (represents seconds in 24 hrs, given in 60 second increments, total length 1440)
Basically I want these data sets to align in time and to know from which data set the data came from (which V and section)
If two data sets align at the same time, I want to be able to choose which data set I’d prefer (to give preference to section A)
Any gaps in time when none of the data lines up with the time vector, I want those values to be 0
If there are two data sets that align in time, I would like to create a secondary matrix with the information
Any advice? Thanks!I have four data sets (K,L,M,N) that look at Y-Axis over 24 hours in seconds given in 60 second time intervals ( time, elevation matrix), all with different matrix lengths from two different sections (two sets from each section (A or B))
The time in these data sets is not continuous.
I want to combine the data and align them in a chronological time vector that spans 1: 86400 (represents seconds in 24 hrs, given in 60 second increments, total length 1440)
Basically I want these data sets to align in time and to know from which data set the data came from (which V and section)
If two data sets align at the same time, I want to be able to choose which data set I’d prefer (to give preference to section A)
Any gaps in time when none of the data lines up with the time vector, I want those values to be 0
If there are two data sets that align in time, I would like to create a secondary matrix with the information
Any advice? Thanks! I have four data sets (K,L,M,N) that look at Y-Axis over 24 hours in seconds given in 60 second time intervals ( time, elevation matrix), all with different matrix lengths from two different sections (two sets from each section (A or B))
The time in these data sets is not continuous.
I want to combine the data and align them in a chronological time vector that spans 1: 86400 (represents seconds in 24 hrs, given in 60 second increments, total length 1440)
Basically I want these data sets to align in time and to know from which data set the data came from (which V and section)
If two data sets align at the same time, I want to be able to choose which data set I’d prefer (to give preference to section A)
Any gaps in time when none of the data lines up with the time vector, I want those values to be 0
If there are two data sets that align in time, I would like to create a secondary matrix with the information
Any advice? Thanks! discontinous matrix, chronological MATLAB Answers — New Questions
How to calculate accuracy from confusion matrix?
How to calculate accuracy from confusion matrix?How to calculate accuracy from confusion matrix? How to calculate accuracy from confusion matrix? accuracy MATLAB Answers — New Questions
How can I find the FFT of a time series when the samples are not equally spaced?
How do I find the FFT of a time series with nonuniformly spaced samples?How do I find the FFT of a time series with nonuniformly spaced samples? How do I find the FFT of a time series with nonuniformly spaced samples? non-constant, fixed, variable, step, fft, random, randomly, spaced, data MATLAB Answers — New Questions
Returning an array of colors from a double image
I am trying to write a function that takes a type double image as input and returns an array of the colors in that image. The returned colors are supposed to be in a matrix form. The colors in my existing image are red, green, blue, white, and yellow. I can’t get my head around this. Any suggestions?I am trying to write a function that takes a type double image as input and returns an array of the colors in that image. The returned colors are supposed to be in a matrix form. The colors in my existing image are red, green, blue, white, and yellow. I can’t get my head around this. Any suggestions? I am trying to write a function that takes a type double image as input and returns an array of the colors in that image. The returned colors are supposed to be in a matrix form. The colors in my existing image are red, green, blue, white, and yellow. I can’t get my head around this. Any suggestions? matrix array, gamut of colors in image MATLAB Answers — New Questions
How to plot the selected column on app.UItable .
Hi all,
I am working on developing an application in matalb. The Run botton will import the excel file and display the columns in the table. I want to program the plot botton in such a way that once the columns are selected in the app.UItable and plot botton clicked by the user. A plot is generated in the app.UIaxes.
I am getting difficulty in coding the second portion where I want to select the column and plot them.
Any help will be greatly appreciated.
Thank youHi all,
I am working on developing an application in matalb. The Run botton will import the excel file and display the columns in the table. I want to program the plot botton in such a way that once the columns are selected in the app.UItable and plot botton clicked by the user. A plot is generated in the app.UIaxes.
I am getting difficulty in coding the second portion where I want to select the column and plot them.
Any help will be greatly appreciated.
Thank you Hi all,
I am working on developing an application in matalb. The Run botton will import the excel file and display the columns in the table. I want to program the plot botton in such a way that once the columns are selected in the app.UItable and plot botton clicked by the user. A plot is generated in the app.UIaxes.
I am getting difficulty in coding the second portion where I want to select the column and plot them.
Any help will be greatly appreciated.
Thank you appdesigner MATLAB Answers — New Questions
Change working directory on a Linux based server
I wrote a script that opens Medical Image Labeler and loads some images in it to be annotated by the user. When the command medicalImageLabeler(gTruth) is executed, the app opens and a popup window (see figure) asks the user to select the path of the new session folder and to enter the name of the session folder. I want the predefined path of the session folder to be the same of the current working directory.
For example: if the current working directory is C:UsersMynameDocuments, the predefined folder for the new Medical Image Labeler’s session has to be C:UsersMynameDocuments.
On my Windows PC I was able to obtain this behavior by setting the working directory with cd, pointing to the desired path (e.g. cd(userFolder) where userFolder = "C:UsersMynameDocuments").
The solution above doesn’t seem to work in the PCs connected to my department server, which run Linux. In this case the predefined folder for savings in the Medical Image Labeler app is always the MATLAB folder (e.g. C:UsersMynameDocumentsMATLAB or similar in the linux environment, I don’t rememeber exactly the folder path) even if run the code in a different folder and even if I change the working directory with cd before opening Medical Image Labeler.
Could it be a problem due to the different operating system? Is there a way to fix it?I wrote a script that opens Medical Image Labeler and loads some images in it to be annotated by the user. When the command medicalImageLabeler(gTruth) is executed, the app opens and a popup window (see figure) asks the user to select the path of the new session folder and to enter the name of the session folder. I want the predefined path of the session folder to be the same of the current working directory.
For example: if the current working directory is C:UsersMynameDocuments, the predefined folder for the new Medical Image Labeler’s session has to be C:UsersMynameDocuments.
On my Windows PC I was able to obtain this behavior by setting the working directory with cd, pointing to the desired path (e.g. cd(userFolder) where userFolder = "C:UsersMynameDocuments").
The solution above doesn’t seem to work in the PCs connected to my department server, which run Linux. In this case the predefined folder for savings in the Medical Image Labeler app is always the MATLAB folder (e.g. C:UsersMynameDocumentsMATLAB or similar in the linux environment, I don’t rememeber exactly the folder path) even if run the code in a different folder and even if I change the working directory with cd before opening Medical Image Labeler.
Could it be a problem due to the different operating system? Is there a way to fix it? I wrote a script that opens Medical Image Labeler and loads some images in it to be annotated by the user. When the command medicalImageLabeler(gTruth) is executed, the app opens and a popup window (see figure) asks the user to select the path of the new session folder and to enter the name of the session folder. I want the predefined path of the session folder to be the same of the current working directory.
For example: if the current working directory is C:UsersMynameDocuments, the predefined folder for the new Medical Image Labeler’s session has to be C:UsersMynameDocuments.
On my Windows PC I was able to obtain this behavior by setting the working directory with cd, pointing to the desired path (e.g. cd(userFolder) where userFolder = "C:UsersMynameDocuments").
The solution above doesn’t seem to work in the PCs connected to my department server, which run Linux. In this case the predefined folder for savings in the Medical Image Labeler app is always the MATLAB folder (e.g. C:UsersMynameDocumentsMATLAB or similar in the linux environment, I don’t rememeber exactly the folder path) even if run the code in a different folder and even if I change the working directory with cd before opening Medical Image Labeler.
Could it be a problem due to the different operating system? Is there a way to fix it? medical image labeler, linux, windows, cd, path, working directory MATLAB Answers — New Questions
Reading CR2 (Canon RAW) images into MATLAB
Hi,
I was wondering if anyone could help me to read in some CR2 images into MATLAB?
I have tried just using imread but it just reads the image as an 8 bit. I can used Adobe’s DNG converter as people have suggested but would rather have the whole code automated. Other questions like this are a few years old so was hoping some people had new suggestions.
Thanks!Hi,
I was wondering if anyone could help me to read in some CR2 images into MATLAB?
I have tried just using imread but it just reads the image as an 8 bit. I can used Adobe’s DNG converter as people have suggested but would rather have the whole code automated. Other questions like this are a few years old so was hoping some people had new suggestions.
Thanks! Hi,
I was wondering if anyone could help me to read in some CR2 images into MATLAB?
I have tried just using imread but it just reads the image as an 8 bit. I can used Adobe’s DNG converter as people have suggested but would rather have the whole code automated. Other questions like this are a few years old so was hoping some people had new suggestions.
Thanks! raw file, image processing, imread, canon, cr2, read in raw MATLAB Answers — New Questions
How can I programmatically create a new MATLAB script and paste string from system clipboard to it in MATLAB R2021b?
I am using MATLAB R2021b, and I have copied some text to my system clipboard. Is there a way that I can programmatically create a new MATLAB script and then paste the text from system clipboard to it?I am using MATLAB R2021b, and I have copied some text to my system clipboard. Is there a way that I can programmatically create a new MATLAB script and then paste the text from system clipboard to it? I am using MATLAB R2021b, and I have copied some text to my system clipboard. Is there a way that I can programmatically create a new MATLAB script and then paste the text from system clipboard to it? clipboard, fopen, fprintf MATLAB Answers — New Questions
Create Class that is both Heterogeneous and a Handle class
2 things.
1) I am looking to create a class that is both a handle class object which allows reference copies of that first object to be distributed / moved which may edit the contents of the first class object AND also be "matlab.mixin.Heterogeneous" which allows there to be an array of objects that differ in their specific class, but are all derived from one root class. In this case that I am looking for all these objects root and derived to also be handel classes.
2) I’m looking for some way to add/remove oject handles from an object’s properties dynamically. I’m not sure how this is normally handeled is Object Oriented Programming, where objects are moved between other objects like people moving form one location to another location.
For example, if I were to simulate people at a obstical course, I would have a class called People, and a root class called Locations for which there are derived classes from, like Swing, Slide, RockWall exe. In this example I want the people object to have a handle to their current location (object), and the different location classes to have a handle to what person is persent, and what location is next in the obstical course after the current one.
Alternativly, if there is maybe a better way of structuring this then I’ve mentioned I would like to know.
classdef Location < matlab.mixin.Heterogeneous %< handle ??????????? NOT SURE HOW MAKE THIS A HANDLE
% "Location" objects are able to change properties of "Person" obj and
% "Location" obj through the handles stored in this classes local properties
properties
locationID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
person (1,1) Person %handle ref, so this class may make changes to it
%next location in the obstical course:
nextLocation (1,1) Location %handle ref, so this class may make changes to it
end
methods
function movePerson(NewLocation,Person)
%find person’s prev location
prevLocation = Person.currentLocation;
%check if new Location’s person is empty
if isempty(NewLocation.person)
%set person’s prev location to empty
clear(prevLocation.person);%????????? NOT SURE HOW TO DO THIS
%Update Location’s person property
NewLocation.person = Person; %copy person handle to location obj
%Update Person’s Location property
Person.currentLocation = NewLocation; %copy location handel to person obj
end
end
end
end
classdef Swing < Location %< handle
methods
function done = sendNextLocation(Location)
if isempty(Location.nextLocation.person) %Swing objects may only accept one person at at a time
Location.AddPerson(Location.nextLocation,Location.person);
Location.RemovePerson(Location);
done = 1;
else
done = 0;
end
end
end
end
classdef Person < handle
properties
ID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
currentLocation (1,1) Location
end
end2 things.
1) I am looking to create a class that is both a handle class object which allows reference copies of that first object to be distributed / moved which may edit the contents of the first class object AND also be "matlab.mixin.Heterogeneous" which allows there to be an array of objects that differ in their specific class, but are all derived from one root class. In this case that I am looking for all these objects root and derived to also be handel classes.
2) I’m looking for some way to add/remove oject handles from an object’s properties dynamically. I’m not sure how this is normally handeled is Object Oriented Programming, where objects are moved between other objects like people moving form one location to another location.
For example, if I were to simulate people at a obstical course, I would have a class called People, and a root class called Locations for which there are derived classes from, like Swing, Slide, RockWall exe. In this example I want the people object to have a handle to their current location (object), and the different location classes to have a handle to what person is persent, and what location is next in the obstical course after the current one.
Alternativly, if there is maybe a better way of structuring this then I’ve mentioned I would like to know.
classdef Location < matlab.mixin.Heterogeneous %< handle ??????????? NOT SURE HOW MAKE THIS A HANDLE
% "Location" objects are able to change properties of "Person" obj and
% "Location" obj through the handles stored in this classes local properties
properties
locationID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
person (1,1) Person %handle ref, so this class may make changes to it
%next location in the obstical course:
nextLocation (1,1) Location %handle ref, so this class may make changes to it
end
methods
function movePerson(NewLocation,Person)
%find person’s prev location
prevLocation = Person.currentLocation;
%check if new Location’s person is empty
if isempty(NewLocation.person)
%set person’s prev location to empty
clear(prevLocation.person);%????????? NOT SURE HOW TO DO THIS
%Update Location’s person property
NewLocation.person = Person; %copy person handle to location obj
%Update Person’s Location property
Person.currentLocation = NewLocation; %copy location handel to person obj
end
end
end
end
classdef Swing < Location %< handle
methods
function done = sendNextLocation(Location)
if isempty(Location.nextLocation.person) %Swing objects may only accept one person at at a time
Location.AddPerson(Location.nextLocation,Location.person);
Location.RemovePerson(Location);
done = 1;
else
done = 0;
end
end
end
end
classdef Person < handle
properties
ID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
currentLocation (1,1) Location
end
end 2 things.
1) I am looking to create a class that is both a handle class object which allows reference copies of that first object to be distributed / moved which may edit the contents of the first class object AND also be "matlab.mixin.Heterogeneous" which allows there to be an array of objects that differ in their specific class, but are all derived from one root class. In this case that I am looking for all these objects root and derived to also be handel classes.
2) I’m looking for some way to add/remove oject handles from an object’s properties dynamically. I’m not sure how this is normally handeled is Object Oriented Programming, where objects are moved between other objects like people moving form one location to another location.
For example, if I were to simulate people at a obstical course, I would have a class called People, and a root class called Locations for which there are derived classes from, like Swing, Slide, RockWall exe. In this example I want the people object to have a handle to their current location (object), and the different location classes to have a handle to what person is persent, and what location is next in the obstical course after the current one.
Alternativly, if there is maybe a better way of structuring this then I’ve mentioned I would like to know.
classdef Location < matlab.mixin.Heterogeneous %< handle ??????????? NOT SURE HOW MAKE THIS A HANDLE
% "Location" objects are able to change properties of "Person" obj and
% "Location" obj through the handles stored in this classes local properties
properties
locationID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
person (1,1) Person %handle ref, so this class may make changes to it
%next location in the obstical course:
nextLocation (1,1) Location %handle ref, so this class may make changes to it
end
methods
function movePerson(NewLocation,Person)
%find person’s prev location
prevLocation = Person.currentLocation;
%check if new Location’s person is empty
if isempty(NewLocation.person)
%set person’s prev location to empty
clear(prevLocation.person);%????????? NOT SURE HOW TO DO THIS
%Update Location’s person property
NewLocation.person = Person; %copy person handle to location obj
%Update Person’s Location property
Person.currentLocation = NewLocation; %copy location handel to person obj
end
end
end
end
classdef Swing < Location %< handle
methods
function done = sendNextLocation(Location)
if isempty(Location.nextLocation.person) %Swing objects may only accept one person at at a time
Location.AddPerson(Location.nextLocation,Location.person);
Location.RemovePerson(Location);
done = 1;
else
done = 0;
end
end
end
end
classdef Person < handle
properties
ID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
currentLocation (1,1) Location
end
end class, handles MATLAB Answers — New Questions
Saving and Restoring Simulation States in an External Application from a Code-Generated Simulink Model with Custom S-Functions
I have a fixed-step Simulink model that includes a referenced model with a custom S-function. This S-function is built with the legacy code tool using a DLL that was compiled from Ada and C code. I plan to autocode this entire Simulink model into a library, which I intend to use in an external non-Matlab real time environment with optional man-in-the-loop inputs. In this external environment, we want to be able to save the simulation’s state at a certain point and then load it back later to continue the simulation repeatably.
We’re in a planning phase and I need to determine whether this is feasible. I’ve looked through some of the documentation and other questions but this use case seems a little out of the ordinary, and it’s not clear to me that the RestoreOperatingPoint etc will work in this case. Will RestoreOperatingPoint work in this scenario, or is there another approach?I have a fixed-step Simulink model that includes a referenced model with a custom S-function. This S-function is built with the legacy code tool using a DLL that was compiled from Ada and C code. I plan to autocode this entire Simulink model into a library, which I intend to use in an external non-Matlab real time environment with optional man-in-the-loop inputs. In this external environment, we want to be able to save the simulation’s state at a certain point and then load it back later to continue the simulation repeatably.
We’re in a planning phase and I need to determine whether this is feasible. I’ve looked through some of the documentation and other questions but this use case seems a little out of the ordinary, and it’s not clear to me that the RestoreOperatingPoint etc will work in this case. Will RestoreOperatingPoint work in this scenario, or is there another approach? I have a fixed-step Simulink model that includes a referenced model with a custom S-function. This S-function is built with the legacy code tool using a DLL that was compiled from Ada and C code. I plan to autocode this entire Simulink model into a library, which I intend to use in an external non-Matlab real time environment with optional man-in-the-loop inputs. In this external environment, we want to be able to save the simulation’s state at a certain point and then load it back later to continue the simulation repeatably.
We’re in a planning phase and I need to determine whether this is feasible. I’ve looked through some of the documentation and other questions but this use case seems a little out of the ordinary, and it’s not clear to me that the RestoreOperatingPoint etc will work in this case. Will RestoreOperatingPoint work in this scenario, or is there another approach? simulink, code generation, s-function, operating point, ada, c++ MATLAB Answers — New Questions
3D Visualization of Items Arrangement
How do I get the 3D visualization of items in the bin from this algorithm?
%
% Copyright (c) 2015, Yarpiz (www.yarpiz.com)
% All rights reserved. Please read the "license.txt" for license terms.
%
% Project Code: YPAP105
% Project Title: Solving Bin Packing Problem using PSO, FA and IWO
% Publisher: Yarpiz (www.yarpiz.com)
%
% Developer: S. Mostapha Kalami Heris (Member of Yarpiz Team)
%
% Contact Info: sm.kalami@gmail.com, info@yarpiz.com
%
clc;
clear;
close all;
%% Problem Definition
model = CreateModel(); % Create Bin Packing Model
CostFunction = @(x) BinPackingCost(x, model); % Objective Function
nVar = 2*model.n-1; % Number of Decision Variables
VarSize = [1 nVar]; % Decision Variables Matrix Size
VarMin = 0; % Lower Bound of Decision Variables
VarMax = 1; % Upper Bound of Decision Variables
%% PSO Parameters
MaxIt=50; % Maximum Number of Iterations
nPop=20; % Population Size (Swarm Size)
% PSO Parameters
w=1; % Inertia Weight
wdamp=0.99; % Inertia Weight Damping Ratio
c1=1.5; % Personal Learning Coefficient
c2=2.0; % Global Learning Coefficient
% If you would like to use Constriction Coefficients for PSO,
% uncomment the following block and comment the above set of parameters.
% % Constriction Coefficients
% phi1=2.05;
% phi2=2.05;
% phi=phi1+phi2;
% chi=2/(phi-2+sqrt(phi^2-4*phi));
% w=chi; % Inertia Weight
% wdamp=1; % Inertia Weight Damping Ratio
% c1=chi*phi1; % Personal Learning Coefficient
% c2=chi*phi2; % Global Learning Coefficient
% Velocity Limits
VelMax=0.1*(VarMax-VarMin);
VelMin=-VelMax;
nParticleMutation = 2; % Number of Mutations Performed on Each Particle
nGlobalBestMutation = 5; % Number of Mutations Performed on Global Best
%% Initialization
empty_particle.Position=[];
empty_particle.Cost=[];
empty_particle.Sol=[];
empty_particle.Velocity=[];
empty_particle.Best.Position=[];
empty_particle.Best.Cost=[];
empty_particle.Best.Sol=[];
particle=repmat(empty_particle,nPop,1);
GlobalBest.Cost=inf;
for i=1:nPop
% Initialize Position
particle(i).Position=unifrnd(VarMin,VarMax,VarSize);
% Initialize Velocity
particle(i).Velocity=zeros(VarSize);
% Evaluation
[particle(i).Cost, particle(i).Sol]=CostFunction(particle(i).Position);
% Update Personal Best
particle(i).Best.Position=particle(i).Position;
particle(i).Best.Cost=particle(i).Cost;
particle(i).Best.Sol=particle(i).Sol;
% Update Global Best
if particle(i).Best.Cost<GlobalBest.Cost
GlobalBest=particle(i).Best;
end
end
BestCost=zeros(MaxIt,1);
%% PSO Main Loop
for it=1:MaxIt
for i=1:nPop
% Update Velocity
particle(i).Velocity = w*particle(i).Velocity …
+c1*rand(VarSize).*(particle(i).Best.Position-particle(i).Position) …
+c2*rand(VarSize).*(GlobalBest.Position-particle(i).Position);
% Apply Velocity Limits
particle(i).Velocity = max(particle(i).Velocity,VelMin);
particle(i).Velocity = min(particle(i).Velocity,VelMax);
% Update Position
particle(i).Position = particle(i).Position + particle(i).Velocity;
% Velocity Mirror Effect
IsOutside=(particle(i).Position<VarMin | particle(i).Position>VarMax);
particle(i).Velocity(IsOutside)=-particle(i).Velocity(IsOutside);
% Apply Position Limits
particle(i).Position = max(particle(i).Position,VarMin);
particle(i).Position = min(particle(i).Position,VarMax);
% Evaluation
[particle(i).Cost, particle(i).Sol] = CostFunction(particle(i).Position);
% Perform Mutation
for j=1:nParticleMutation
NewParticle = particle(i);
NewParticle.Position = Mutate(particle(i).Position);
[NewParticle.Cost, NewParticle.Sol] = CostFunction(NewParticle.Position);
if NewParticle.Cost <= particle(i).Cost
particle(i) = NewParticle;
end
end
% Update Personal Best
if particle(i).Cost<particle(i).Best.Cost
particle(i).Best.Position=particle(i).Position;
particle(i).Best.Cost=particle(i).Cost;
particle(i).Best.Sol=particle(i).Sol;
% Update Global Best
if particle(i).Best.Cost<GlobalBest.Cost
GlobalBest=particle(i).Best;
end
end
end
% Perform Mutation on Global Best
for i=1:nGlobalBestMutation
NewParticle = GlobalBest;
NewParticle.Position = Mutate(GlobalBest.Position);
[NewParticle.Cost, NewParticle.Sol] = CostFunction(NewParticle.Position);
if NewParticle.Cost <= GlobalBest.Cost
GlobalBest = NewParticle;
end
end
BestCost(it)=GlobalBest.Cost;
disp([‘Iteration ‘ num2str(it) ‘: Best Cost = ‘ num2str(BestCost(it))]);
w=w*wdamp;
end
BestSol = GlobalBest;
%% Results
figure;
plot(BestCost,’LineWidth’,2);
xlabel(‘Iteration’);
ylabel(‘Best Cost’);
grid on;
i got this algorithm from https://www.mathworks.com/matlabcentral/fileexchange/53111-bin-packing-problem-using-ga-pso-fa-and-iwoHow do I get the 3D visualization of items in the bin from this algorithm?
%
% Copyright (c) 2015, Yarpiz (www.yarpiz.com)
% All rights reserved. Please read the "license.txt" for license terms.
%
% Project Code: YPAP105
% Project Title: Solving Bin Packing Problem using PSO, FA and IWO
% Publisher: Yarpiz (www.yarpiz.com)
%
% Developer: S. Mostapha Kalami Heris (Member of Yarpiz Team)
%
% Contact Info: sm.kalami@gmail.com, info@yarpiz.com
%
clc;
clear;
close all;
%% Problem Definition
model = CreateModel(); % Create Bin Packing Model
CostFunction = @(x) BinPackingCost(x, model); % Objective Function
nVar = 2*model.n-1; % Number of Decision Variables
VarSize = [1 nVar]; % Decision Variables Matrix Size
VarMin = 0; % Lower Bound of Decision Variables
VarMax = 1; % Upper Bound of Decision Variables
%% PSO Parameters
MaxIt=50; % Maximum Number of Iterations
nPop=20; % Population Size (Swarm Size)
% PSO Parameters
w=1; % Inertia Weight
wdamp=0.99; % Inertia Weight Damping Ratio
c1=1.5; % Personal Learning Coefficient
c2=2.0; % Global Learning Coefficient
% If you would like to use Constriction Coefficients for PSO,
% uncomment the following block and comment the above set of parameters.
% % Constriction Coefficients
% phi1=2.05;
% phi2=2.05;
% phi=phi1+phi2;
% chi=2/(phi-2+sqrt(phi^2-4*phi));
% w=chi; % Inertia Weight
% wdamp=1; % Inertia Weight Damping Ratio
% c1=chi*phi1; % Personal Learning Coefficient
% c2=chi*phi2; % Global Learning Coefficient
% Velocity Limits
VelMax=0.1*(VarMax-VarMin);
VelMin=-VelMax;
nParticleMutation = 2; % Number of Mutations Performed on Each Particle
nGlobalBestMutation = 5; % Number of Mutations Performed on Global Best
%% Initialization
empty_particle.Position=[];
empty_particle.Cost=[];
empty_particle.Sol=[];
empty_particle.Velocity=[];
empty_particle.Best.Position=[];
empty_particle.Best.Cost=[];
empty_particle.Best.Sol=[];
particle=repmat(empty_particle,nPop,1);
GlobalBest.Cost=inf;
for i=1:nPop
% Initialize Position
particle(i).Position=unifrnd(VarMin,VarMax,VarSize);
% Initialize Velocity
particle(i).Velocity=zeros(VarSize);
% Evaluation
[particle(i).Cost, particle(i).Sol]=CostFunction(particle(i).Position);
% Update Personal Best
particle(i).Best.Position=particle(i).Position;
particle(i).Best.Cost=particle(i).Cost;
particle(i).Best.Sol=particle(i).Sol;
% Update Global Best
if particle(i).Best.Cost<GlobalBest.Cost
GlobalBest=particle(i).Best;
end
end
BestCost=zeros(MaxIt,1);
%% PSO Main Loop
for it=1:MaxIt
for i=1:nPop
% Update Velocity
particle(i).Velocity = w*particle(i).Velocity …
+c1*rand(VarSize).*(particle(i).Best.Position-particle(i).Position) …
+c2*rand(VarSize).*(GlobalBest.Position-particle(i).Position);
% Apply Velocity Limits
particle(i).Velocity = max(particle(i).Velocity,VelMin);
particle(i).Velocity = min(particle(i).Velocity,VelMax);
% Update Position
particle(i).Position = particle(i).Position + particle(i).Velocity;
% Velocity Mirror Effect
IsOutside=(particle(i).Position<VarMin | particle(i).Position>VarMax);
particle(i).Velocity(IsOutside)=-particle(i).Velocity(IsOutside);
% Apply Position Limits
particle(i).Position = max(particle(i).Position,VarMin);
particle(i).Position = min(particle(i).Position,VarMax);
% Evaluation
[particle(i).Cost, particle(i).Sol] = CostFunction(particle(i).Position);
% Perform Mutation
for j=1:nParticleMutation
NewParticle = particle(i);
NewParticle.Position = Mutate(particle(i).Position);
[NewParticle.Cost, NewParticle.Sol] = CostFunction(NewParticle.Position);
if NewParticle.Cost <= particle(i).Cost
particle(i) = NewParticle;
end
end
% Update Personal Best
if particle(i).Cost<particle(i).Best.Cost
particle(i).Best.Position=particle(i).Position;
particle(i).Best.Cost=particle(i).Cost;
particle(i).Best.Sol=particle(i).Sol;
% Update Global Best
if particle(i).Best.Cost<GlobalBest.Cost
GlobalBest=particle(i).Best;
end
end
end
% Perform Mutation on Global Best
for i=1:nGlobalBestMutation
NewParticle = GlobalBest;
NewParticle.Position = Mutate(GlobalBest.Position);
[NewParticle.Cost, NewParticle.Sol] = CostFunction(NewParticle.Position);
if NewParticle.Cost <= GlobalBest.Cost
GlobalBest = NewParticle;
end
end
BestCost(it)=GlobalBest.Cost;
disp([‘Iteration ‘ num2str(it) ‘: Best Cost = ‘ num2str(BestCost(it))]);
w=w*wdamp;
end
BestSol = GlobalBest;
%% Results
figure;
plot(BestCost,’LineWidth’,2);
xlabel(‘Iteration’);
ylabel(‘Best Cost’);
grid on;
i got this algorithm from https://www.mathworks.com/matlabcentral/fileexchange/53111-bin-packing-problem-using-ga-pso-fa-and-iwo How do I get the 3D visualization of items in the bin from this algorithm?
%
% Copyright (c) 2015, Yarpiz (www.yarpiz.com)
% All rights reserved. Please read the "license.txt" for license terms.
%
% Project Code: YPAP105
% Project Title: Solving Bin Packing Problem using PSO, FA and IWO
% Publisher: Yarpiz (www.yarpiz.com)
%
% Developer: S. Mostapha Kalami Heris (Member of Yarpiz Team)
%
% Contact Info: sm.kalami@gmail.com, info@yarpiz.com
%
clc;
clear;
close all;
%% Problem Definition
model = CreateModel(); % Create Bin Packing Model
CostFunction = @(x) BinPackingCost(x, model); % Objective Function
nVar = 2*model.n-1; % Number of Decision Variables
VarSize = [1 nVar]; % Decision Variables Matrix Size
VarMin = 0; % Lower Bound of Decision Variables
VarMax = 1; % Upper Bound of Decision Variables
%% PSO Parameters
MaxIt=50; % Maximum Number of Iterations
nPop=20; % Population Size (Swarm Size)
% PSO Parameters
w=1; % Inertia Weight
wdamp=0.99; % Inertia Weight Damping Ratio
c1=1.5; % Personal Learning Coefficient
c2=2.0; % Global Learning Coefficient
% If you would like to use Constriction Coefficients for PSO,
% uncomment the following block and comment the above set of parameters.
% % Constriction Coefficients
% phi1=2.05;
% phi2=2.05;
% phi=phi1+phi2;
% chi=2/(phi-2+sqrt(phi^2-4*phi));
% w=chi; % Inertia Weight
% wdamp=1; % Inertia Weight Damping Ratio
% c1=chi*phi1; % Personal Learning Coefficient
% c2=chi*phi2; % Global Learning Coefficient
% Velocity Limits
VelMax=0.1*(VarMax-VarMin);
VelMin=-VelMax;
nParticleMutation = 2; % Number of Mutations Performed on Each Particle
nGlobalBestMutation = 5; % Number of Mutations Performed on Global Best
%% Initialization
empty_particle.Position=[];
empty_particle.Cost=[];
empty_particle.Sol=[];
empty_particle.Velocity=[];
empty_particle.Best.Position=[];
empty_particle.Best.Cost=[];
empty_particle.Best.Sol=[];
particle=repmat(empty_particle,nPop,1);
GlobalBest.Cost=inf;
for i=1:nPop
% Initialize Position
particle(i).Position=unifrnd(VarMin,VarMax,VarSize);
% Initialize Velocity
particle(i).Velocity=zeros(VarSize);
% Evaluation
[particle(i).Cost, particle(i).Sol]=CostFunction(particle(i).Position);
% Update Personal Best
particle(i).Best.Position=particle(i).Position;
particle(i).Best.Cost=particle(i).Cost;
particle(i).Best.Sol=particle(i).Sol;
% Update Global Best
if particle(i).Best.Cost<GlobalBest.Cost
GlobalBest=particle(i).Best;
end
end
BestCost=zeros(MaxIt,1);
%% PSO Main Loop
for it=1:MaxIt
for i=1:nPop
% Update Velocity
particle(i).Velocity = w*particle(i).Velocity …
+c1*rand(VarSize).*(particle(i).Best.Position-particle(i).Position) …
+c2*rand(VarSize).*(GlobalBest.Position-particle(i).Position);
% Apply Velocity Limits
particle(i).Velocity = max(particle(i).Velocity,VelMin);
particle(i).Velocity = min(particle(i).Velocity,VelMax);
% Update Position
particle(i).Position = particle(i).Position + particle(i).Velocity;
% Velocity Mirror Effect
IsOutside=(particle(i).Position<VarMin | particle(i).Position>VarMax);
particle(i).Velocity(IsOutside)=-particle(i).Velocity(IsOutside);
% Apply Position Limits
particle(i).Position = max(particle(i).Position,VarMin);
particle(i).Position = min(particle(i).Position,VarMax);
% Evaluation
[particle(i).Cost, particle(i).Sol] = CostFunction(particle(i).Position);
% Perform Mutation
for j=1:nParticleMutation
NewParticle = particle(i);
NewParticle.Position = Mutate(particle(i).Position);
[NewParticle.Cost, NewParticle.Sol] = CostFunction(NewParticle.Position);
if NewParticle.Cost <= particle(i).Cost
particle(i) = NewParticle;
end
end
% Update Personal Best
if particle(i).Cost<particle(i).Best.Cost
particle(i).Best.Position=particle(i).Position;
particle(i).Best.Cost=particle(i).Cost;
particle(i).Best.Sol=particle(i).Sol;
% Update Global Best
if particle(i).Best.Cost<GlobalBest.Cost
GlobalBest=particle(i).Best;
end
end
end
% Perform Mutation on Global Best
for i=1:nGlobalBestMutation
NewParticle = GlobalBest;
NewParticle.Position = Mutate(GlobalBest.Position);
[NewParticle.Cost, NewParticle.Sol] = CostFunction(NewParticle.Position);
if NewParticle.Cost <= GlobalBest.Cost
GlobalBest = NewParticle;
end
end
BestCost(it)=GlobalBest.Cost;
disp([‘Iteration ‘ num2str(it) ‘: Best Cost = ‘ num2str(BestCost(it))]);
w=w*wdamp;
end
BestSol = GlobalBest;
%% Results
figure;
plot(BestCost,’LineWidth’,2);
xlabel(‘Iteration’);
ylabel(‘Best Cost’);
grid on;
i got this algorithm from https://www.mathworks.com/matlabcentral/fileexchange/53111-bin-packing-problem-using-ga-pso-fa-and-iwo pso, particle swarm optimization, 3d plots, bin packing, matlab, algorithm MATLAB Answers — New Questions
How to match matrix elements for a condition?
I am working on App Designer. I have a matrix and want to match the elements 3 by 3 with a condition. The condition is that addition of 3 elements must be near at a value.
I already can match them by making the addition from minimum to maximum, but it does not seem to be optimal. So, I want them to be around a value.I am working on App Designer. I have a matrix and want to match the elements 3 by 3 with a condition. The condition is that addition of 3 elements must be near at a value.
I already can match them by making the addition from minimum to maximum, but it does not seem to be optimal. So, I want them to be around a value. I am working on App Designer. I have a matrix and want to match the elements 3 by 3 with a condition. The condition is that addition of 3 elements must be near at a value.
I already can match them by making the addition from minimum to maximum, but it does not seem to be optimal. So, I want them to be around a value. matlab gui, matlab, appdesigner, app designer, data, sort, match MATLAB Answers — New Questions