Tag Archives: matlab
Setting common color maps for categorical images with no ordinal information in the categorical labels
I’m trying to create a common colormap from two different categorical images that are segmentations of brain regions. The labels in "oldsegvis" are an entirely contained subset of the labels in "newsegvis". I’m expecting the same label value (e.g. newseg = 100, oldseg = 100) to return the same color, however, that is not the output behavior I’m observing. I’ve confirmed by looking at the values in the output newsegvis and oldsegvis arrays and by using "Data Tips" that the same values are being assigned different colors. Additionally, in the visualization of the "newsegvis" array, different values are being assigned the same color, which I’ve also confirmed with "Data Tips", even though the number of colors and the number of unique label values are the same. A code snippet is pasted below; I’m sure there’s something simple I’m missing, but would be very appreciative if someone could point it out to me. Thanks!
%% Visualize segmentations
%select section (transverse plane)
newsegvis = squeeze(newvol(:,:,100));
oldsegvis = squeeze(oldvol(:,:,100));
%set colormaps (new segmentations have all old segmentation labels plus
%additional labels)
newsegs = unique(newsegvis);
oldsegs = unique(oldsegvis);
cmap_ov = [0 0 0;rand(length(newsegs)-1,3)];
cmap_orig = cmap_ov(1:length(oldsegs),:);
%visualize segmentations
figure; imagesc(newsegvis); colormap(cmap_ov);
figure; imagesc(oldsegvis); colormap(cmap_orig);I’m trying to create a common colormap from two different categorical images that are segmentations of brain regions. The labels in "oldsegvis" are an entirely contained subset of the labels in "newsegvis". I’m expecting the same label value (e.g. newseg = 100, oldseg = 100) to return the same color, however, that is not the output behavior I’m observing. I’ve confirmed by looking at the values in the output newsegvis and oldsegvis arrays and by using "Data Tips" that the same values are being assigned different colors. Additionally, in the visualization of the "newsegvis" array, different values are being assigned the same color, which I’ve also confirmed with "Data Tips", even though the number of colors and the number of unique label values are the same. A code snippet is pasted below; I’m sure there’s something simple I’m missing, but would be very appreciative if someone could point it out to me. Thanks!
%% Visualize segmentations
%select section (transverse plane)
newsegvis = squeeze(newvol(:,:,100));
oldsegvis = squeeze(oldvol(:,:,100));
%set colormaps (new segmentations have all old segmentation labels plus
%additional labels)
newsegs = unique(newsegvis);
oldsegs = unique(oldsegvis);
cmap_ov = [0 0 0;rand(length(newsegs)-1,3)];
cmap_orig = cmap_ov(1:length(oldsegs),:);
%visualize segmentations
figure; imagesc(newsegvis); colormap(cmap_ov);
figure; imagesc(oldsegvis); colormap(cmap_orig); I’m trying to create a common colormap from two different categorical images that are segmentations of brain regions. The labels in "oldsegvis" are an entirely contained subset of the labels in "newsegvis". I’m expecting the same label value (e.g. newseg = 100, oldseg = 100) to return the same color, however, that is not the output behavior I’m observing. I’ve confirmed by looking at the values in the output newsegvis and oldsegvis arrays and by using "Data Tips" that the same values are being assigned different colors. Additionally, in the visualization of the "newsegvis" array, different values are being assigned the same color, which I’ve also confirmed with "Data Tips", even though the number of colors and the number of unique label values are the same. A code snippet is pasted below; I’m sure there’s something simple I’m missing, but would be very appreciative if someone could point it out to me. Thanks!
%% Visualize segmentations
%select section (transverse plane)
newsegvis = squeeze(newvol(:,:,100));
oldsegvis = squeeze(oldvol(:,:,100));
%set colormaps (new segmentations have all old segmentation labels plus
%additional labels)
newsegs = unique(newsegvis);
oldsegs = unique(oldsegvis);
cmap_ov = [0 0 0;rand(length(newsegs)-1,3)];
cmap_orig = cmap_ov(1:length(oldsegs),:);
%visualize segmentations
figure; imagesc(newsegvis); colormap(cmap_ov);
figure; imagesc(oldsegvis); colormap(cmap_orig); colormap, imagesc MATLAB Answers — New Questions
Support for NVIDIA RTX A1000
I am evaluating if a Dell laptop with an NVIDIA RTX A1000 graphics card can take advantage of the GPU accleration in Matlab. The NVIDIA site does not list the ‘compute capability’ of the RTX A1000 in the table of current or legacy graphic cards.I am evaluating if a Dell laptop with an NVIDIA RTX A1000 graphics card can take advantage of the GPU accleration in Matlab. The NVIDIA site does not list the ‘compute capability’ of the RTX A1000 in the table of current or legacy graphic cards. I am evaluating if a Dell laptop with an NVIDIA RTX A1000 graphics card can take advantage of the GPU accleration in Matlab. The NVIDIA site does not list the ‘compute capability’ of the RTX A1000 in the table of current or legacy graphic cards. nvidia rtx a1000 MATLAB Answers — New Questions
What does it mean “/Multiple” after variable name in *.mat file?
I have *.mat files exported by Bruker Opus program. When I select these files Matlab lists the variables contained in that file. However, after each variable name there is a /Multiple note, (see figure).
When I click on the file it does not load anything.
What does it mean the "/Multiple"? How to load these files?I have *.mat files exported by Bruker Opus program. When I select these files Matlab lists the variables contained in that file. However, after each variable name there is a /Multiple note, (see figure).
When I click on the file it does not load anything.
What does it mean the "/Multiple"? How to load these files? I have *.mat files exported by Bruker Opus program. When I select these files Matlab lists the variables contained in that file. However, after each variable name there is a /Multiple note, (see figure).
When I click on the file it does not load anything.
What does it mean the "/Multiple"? How to load these files? bruker, opus, mat files, /multiple flag? MATLAB Answers — New Questions
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