Tag Archives: matlab
Use fixed colormap or colorbar scale for series of 3D bar graphs in video animation
I’ve been able to incorporate code from this answer:
https://www.mathworks.com/matlabcentral/answers/98236-how-can-i-color-bars-to-correspond-to-their-heights-when-using-bar3
…in order to set uniform colors to bars in bar3() plots based on height. I would like the color scale to be fixed (10=burgendy, 0=navy) throughout all plots; however, it seems to be relative based on the max/min of each one. I tried setting c.TicksLimit=[0 10] but that didn’t work. It’s quite possible there’s an entirely better/different approach for this 3D visualization. I am open to a changeup but also would appreciate the opportunity to better undestand bar3() and figure properties. Thank you for your time and assistance.
Here’s the current animation produced from the code below to help visualize. Ideally, the initial condition would be all burgendy bars, and the colorbar would be fixed all through the animation from 0 to 10.
function animator(frames)
filename = ‘animation.mp4’;
v=VideoWriter(filename,’MPEG-4′);
v.FrameRate=2;
open(v);
for i1=1:length(frames)
active=frames(:,:,i1);
b=bar3(active);
colormap(turbo(10)); %% Perhaps something ‘smart’ happens here instead of fixed turbo(10)
% to set the colormap based on relative max/min?
set(gca,’ZLim’,[0 10]);
% Copied from above link and properly colors all bars to same color
% based on height
numBars=size(active,1);
numSets=size(active,2);
for i2=1:numSets
zdata=ones(6*numBars,4);
k=1;
for j=0:6:(6*numBars-6)
zdata(j+1:j+6,:)=active(k,i2);
k=k+1;
end
set(b(i2),’Cdata’,zdata)
end
c=colorbar;
c.Ticks=0:10;
% Or maybe something happens here to fix the colorbar scale?
exportgraphics(gca,’temp.png’);
im=imread(‘temp.png’);
im=imresize(im,[560 730]);
writeVideo(v,im);
end
endI’ve been able to incorporate code from this answer:
https://www.mathworks.com/matlabcentral/answers/98236-how-can-i-color-bars-to-correspond-to-their-heights-when-using-bar3
…in order to set uniform colors to bars in bar3() plots based on height. I would like the color scale to be fixed (10=burgendy, 0=navy) throughout all plots; however, it seems to be relative based on the max/min of each one. I tried setting c.TicksLimit=[0 10] but that didn’t work. It’s quite possible there’s an entirely better/different approach for this 3D visualization. I am open to a changeup but also would appreciate the opportunity to better undestand bar3() and figure properties. Thank you for your time and assistance.
Here’s the current animation produced from the code below to help visualize. Ideally, the initial condition would be all burgendy bars, and the colorbar would be fixed all through the animation from 0 to 10.
function animator(frames)
filename = ‘animation.mp4’;
v=VideoWriter(filename,’MPEG-4′);
v.FrameRate=2;
open(v);
for i1=1:length(frames)
active=frames(:,:,i1);
b=bar3(active);
colormap(turbo(10)); %% Perhaps something ‘smart’ happens here instead of fixed turbo(10)
% to set the colormap based on relative max/min?
set(gca,’ZLim’,[0 10]);
% Copied from above link and properly colors all bars to same color
% based on height
numBars=size(active,1);
numSets=size(active,2);
for i2=1:numSets
zdata=ones(6*numBars,4);
k=1;
for j=0:6:(6*numBars-6)
zdata(j+1:j+6,:)=active(k,i2);
k=k+1;
end
set(b(i2),’Cdata’,zdata)
end
c=colorbar;
c.Ticks=0:10;
% Or maybe something happens here to fix the colorbar scale?
exportgraphics(gca,’temp.png’);
im=imread(‘temp.png’);
im=imresize(im,[560 730]);
writeVideo(v,im);
end
end I’ve been able to incorporate code from this answer:
https://www.mathworks.com/matlabcentral/answers/98236-how-can-i-color-bars-to-correspond-to-their-heights-when-using-bar3
…in order to set uniform colors to bars in bar3() plots based on height. I would like the color scale to be fixed (10=burgendy, 0=navy) throughout all plots; however, it seems to be relative based on the max/min of each one. I tried setting c.TicksLimit=[0 10] but that didn’t work. It’s quite possible there’s an entirely better/different approach for this 3D visualization. I am open to a changeup but also would appreciate the opportunity to better undestand bar3() and figure properties. Thank you for your time and assistance.
Here’s the current animation produced from the code below to help visualize. Ideally, the initial condition would be all burgendy bars, and the colorbar would be fixed all through the animation from 0 to 10.
function animator(frames)
filename = ‘animation.mp4’;
v=VideoWriter(filename,’MPEG-4′);
v.FrameRate=2;
open(v);
for i1=1:length(frames)
active=frames(:,:,i1);
b=bar3(active);
colormap(turbo(10)); %% Perhaps something ‘smart’ happens here instead of fixed turbo(10)
% to set the colormap based on relative max/min?
set(gca,’ZLim’,[0 10]);
% Copied from above link and properly colors all bars to same color
% based on height
numBars=size(active,1);
numSets=size(active,2);
for i2=1:numSets
zdata=ones(6*numBars,4);
k=1;
for j=0:6:(6*numBars-6)
zdata(j+1:j+6,:)=active(k,i2);
k=k+1;
end
set(b(i2),’Cdata’,zdata)
end
c=colorbar;
c.Ticks=0:10;
% Or maybe something happens here to fix the colorbar scale?
exportgraphics(gca,’temp.png’);
im=imread(‘temp.png’);
im=imresize(im,[560 730]);
writeVideo(v,im);
end
end 3d plots, colormap MATLAB Answers — New Questions
i want a voltage graph that shows a charging curve from time 0 to 0.08 seconds, followed by a constant voltage from 0.08 to 0.1 seconds. kindly guide me
I want a voltage graph that shows a charging curve from time 0 to 0.08 seconds, followed by a constant voltage from 0.08 to 0.1 seconds. kindly guide meI want a voltage graph that shows a charging curve from time 0 to 0.08 seconds, followed by a constant voltage from 0.08 to 0.1 seconds. kindly guide me I want a voltage graph that shows a charging curve from time 0 to 0.08 seconds, followed by a constant voltage from 0.08 to 0.1 seconds. kindly guide me simulink, matlab MATLAB Answers — New Questions
How to do the filtered back projection?
Dear all,
I want to do the filtered back projection. Here is my code:
First, I created the phantom:
%create the phantom
Z = zeros(99); % create square matrix of zeroes
origin = [round((size(Z,2)-1)/2+1) round((size(Z,1)-1)/2+1)]; % "center" of the matrix
radius = round(sqrt(numel(Z)/(2*pi))); % radius for a circle that fills half the area of the matrix
[xx,yy] = meshgrid((1:size(Z,2))-origin(1),(1:size(Z,1))-origin(2)); % create x and y grid
Z(sqrt(xx.^2 + yy.^2) <= radius) = 1; % set points inside the radius equal to one
imshow(Z); % show the "image"
Second, I transform to frequency domain:
j = fftshift(fft2(Z));
figure, imshow(j)
j1 = log(1+abs(j));
figure ,imshow(j1)
j2 = bar(j1);
Third, should be I multiply my frequency domain with my Ramp Filter. My Ramp filter as here:
% Define parameters
N = 512; % Number of points in the filter
fs = 1000; % Sampling freq. in Hz
f = fs * (-N/2:N/2-1)/N; % Freq. vector
% Creating the ramp filter in the freq. domain
rampFilter = abs(f);
% Plot
figure;
plot(f, rampFilter);
title(‘Ramp Filter’);
xlabel(‘Frequency (Hz)’);
ylabel(‘Amplitude’);
grid on;
But, my problem is I dont know how to multiply my frequency domain with Ramp Filter, as the step number 2 in picture below.
ANYONE CAN HELP ME?Dear all,
I want to do the filtered back projection. Here is my code:
First, I created the phantom:
%create the phantom
Z = zeros(99); % create square matrix of zeroes
origin = [round((size(Z,2)-1)/2+1) round((size(Z,1)-1)/2+1)]; % "center" of the matrix
radius = round(sqrt(numel(Z)/(2*pi))); % radius for a circle that fills half the area of the matrix
[xx,yy] = meshgrid((1:size(Z,2))-origin(1),(1:size(Z,1))-origin(2)); % create x and y grid
Z(sqrt(xx.^2 + yy.^2) <= radius) = 1; % set points inside the radius equal to one
imshow(Z); % show the "image"
Second, I transform to frequency domain:
j = fftshift(fft2(Z));
figure, imshow(j)
j1 = log(1+abs(j));
figure ,imshow(j1)
j2 = bar(j1);
Third, should be I multiply my frequency domain with my Ramp Filter. My Ramp filter as here:
% Define parameters
N = 512; % Number of points in the filter
fs = 1000; % Sampling freq. in Hz
f = fs * (-N/2:N/2-1)/N; % Freq. vector
% Creating the ramp filter in the freq. domain
rampFilter = abs(f);
% Plot
figure;
plot(f, rampFilter);
title(‘Ramp Filter’);
xlabel(‘Frequency (Hz)’);
ylabel(‘Amplitude’);
grid on;
But, my problem is I dont know how to multiply my frequency domain with Ramp Filter, as the step number 2 in picture below.
ANYONE CAN HELP ME? Dear all,
I want to do the filtered back projection. Here is my code:
First, I created the phantom:
%create the phantom
Z = zeros(99); % create square matrix of zeroes
origin = [round((size(Z,2)-1)/2+1) round((size(Z,1)-1)/2+1)]; % "center" of the matrix
radius = round(sqrt(numel(Z)/(2*pi))); % radius for a circle that fills half the area of the matrix
[xx,yy] = meshgrid((1:size(Z,2))-origin(1),(1:size(Z,1))-origin(2)); % create x and y grid
Z(sqrt(xx.^2 + yy.^2) <= radius) = 1; % set points inside the radius equal to one
imshow(Z); % show the "image"
Second, I transform to frequency domain:
j = fftshift(fft2(Z));
figure, imshow(j)
j1 = log(1+abs(j));
figure ,imshow(j1)
j2 = bar(j1);
Third, should be I multiply my frequency domain with my Ramp Filter. My Ramp filter as here:
% Define parameters
N = 512; % Number of points in the filter
fs = 1000; % Sampling freq. in Hz
f = fs * (-N/2:N/2-1)/N; % Freq. vector
% Creating the ramp filter in the freq. domain
rampFilter = abs(f);
% Plot
figure;
plot(f, rampFilter);
title(‘Ramp Filter’);
xlabel(‘Frequency (Hz)’);
ylabel(‘Amplitude’);
grid on;
But, my problem is I dont know how to multiply my frequency domain with Ramp Filter, as the step number 2 in picture below.
ANYONE CAN HELP ME? image analysis, image processing, image acquisition, image segmentation, digital image processing, image MATLAB Answers — New Questions
Extract numeric values from a colormap
Hello everyone
I am trying to extract the numerical values of a variable represented in the following colormap with its respective colorbar (which I also attach in PDF format):
It would be very desirable to be able to create a database based on the spatial deviation from the center of the hexagon along the directions defined by the a1 and a2 vectors as a fraction of a0, being a0 the modulus of the aforementioned vectos:
Any idea?Hello everyone
I am trying to extract the numerical values of a variable represented in the following colormap with its respective colorbar (which I also attach in PDF format):
It would be very desirable to be able to create a database based on the spatial deviation from the center of the hexagon along the directions defined by the a1 and a2 vectors as a fraction of a0, being a0 the modulus of the aforementioned vectos:
Any idea? Hello everyone
I am trying to extract the numerical values of a variable represented in the following colormap with its respective colorbar (which I also attach in PDF format):
It would be very desirable to be able to create a database based on the spatial deviation from the center of the hexagon along the directions defined by the a1 and a2 vectors as a fraction of a0, being a0 the modulus of the aforementioned vectos:
Any idea? colormap, visual data MATLAB Answers — New Questions
How the extract EEG data according to different epoch limits?
Hey there! Currently I got an EEG data with events like "2", "4", "6","8" which mean the outset of different audio stimui. There are 20 kinds of specific audio stimuli with some similar features for each kind of event/trigger. I have the stimuli matrix generated in each experiment which is in the actual stimulating order. so the specific stimulus for each event could be targeted. In each stimulus, there is 1s silence at the begining and and the end and duration of actual voice is from 1s to 2s. I can use the detectSpeech function to find the outset and end of the voice.
Now I want to extract the EEG data with actual audio stimuli and delete the silence areas, which couldn’t be realized by exracting epochs with specific limits(start and end). could you please tell me how to use script to get the EEG epochs with different length?
Thank you very much!Hey there! Currently I got an EEG data with events like "2", "4", "6","8" which mean the outset of different audio stimui. There are 20 kinds of specific audio stimuli with some similar features for each kind of event/trigger. I have the stimuli matrix generated in each experiment which is in the actual stimulating order. so the specific stimulus for each event could be targeted. In each stimulus, there is 1s silence at the begining and and the end and duration of actual voice is from 1s to 2s. I can use the detectSpeech function to find the outset and end of the voice.
Now I want to extract the EEG data with actual audio stimuli and delete the silence areas, which couldn’t be realized by exracting epochs with specific limits(start and end). could you please tell me how to use script to get the EEG epochs with different length?
Thank you very much! Hey there! Currently I got an EEG data with events like "2", "4", "6","8" which mean the outset of different audio stimui. There are 20 kinds of specific audio stimuli with some similar features for each kind of event/trigger. I have the stimuli matrix generated in each experiment which is in the actual stimulating order. so the specific stimulus for each event could be targeted. In each stimulus, there is 1s silence at the begining and and the end and duration of actual voice is from 1s to 2s. I can use the detectSpeech function to find the outset and end of the voice.
Now I want to extract the EEG data with actual audio stimuli and delete the silence areas, which couldn’t be realized by exracting epochs with specific limits(start and end). could you please tell me how to use script to get the EEG epochs with different length?
Thank you very much! eeg, matlab, epoch, extract, audio stimui, event related potential MATLAB Answers — New Questions
How to define line code to block Frequency EEG based on specific range?
I am new on mathalab and programmation, I am loocking for a base script to lock specific range of EEG frequency.
I would like :
to create a script able to detect the frequency from 0 to 20 Hz.
to block some of this frquency.
Thank you for help.I am new on mathalab and programmation, I am loocking for a base script to lock specific range of EEG frequency.
I would like :
to create a script able to detect the frequency from 0 to 20 Hz.
to block some of this frquency.
Thank you for help. I am new on mathalab and programmation, I am loocking for a base script to lock specific range of EEG frequency.
I would like :
to create a script able to detect the frequency from 0 to 20 Hz.
to block some of this frquency.
Thank you for help. eeg, frequency MATLAB Answers — New Questions
Hello everyone! So i am kind of new to MATLAB. I created a UI with tabs, however when i maximise the UI figure, the tabs do not resize along with it. How can i manage this? Thank you in advance.
clear all
clc
%Creating Tabs
fig = uifigure("Name","BISC");
set(fig, ‘Units’, ‘normalized’, ‘Position’, [0.1, 0.1, 0.8, 0.8]);
tg = uitabgroup(fig,’Units’,’normalized’,"Position",[0,0,1,1]);
t1 = uitab(tg,"Title","Data");
tg1 = uitabgroup(t1,’Units’,’normalized’,"Position",[0,0,1,1]);
t3 = uitab(tg1, ‘Title’, ‘Tab 3’);
t4 = uitab(tg1, ‘Title’, ‘Tab 4’);
t2 = uitab(tg,"Title","Plots");
tg2 = uitabgroup(t2,’Units’,’normalized’,"Position",[0,0,1,1]);
t5 = uitab(tg2, ‘Title’, ‘Tab 5’);
t6 = uitab(tg2, ‘Title’, ‘Tab 6’);
t1.Scrollable = "on";
t2.Scrollable = "on";clear all
clc
%Creating Tabs
fig = uifigure("Name","BISC");
set(fig, ‘Units’, ‘normalized’, ‘Position’, [0.1, 0.1, 0.8, 0.8]);
tg = uitabgroup(fig,’Units’,’normalized’,"Position",[0,0,1,1]);
t1 = uitab(tg,"Title","Data");
tg1 = uitabgroup(t1,’Units’,’normalized’,"Position",[0,0,1,1]);
t3 = uitab(tg1, ‘Title’, ‘Tab 3’);
t4 = uitab(tg1, ‘Title’, ‘Tab 4’);
t2 = uitab(tg,"Title","Plots");
tg2 = uitabgroup(t2,’Units’,’normalized’,"Position",[0,0,1,1]);
t5 = uitab(tg2, ‘Title’, ‘Tab 5’);
t6 = uitab(tg2, ‘Title’, ‘Tab 6’);
t1.Scrollable = "on";
t2.Scrollable = "on"; clear all
clc
%Creating Tabs
fig = uifigure("Name","BISC");
set(fig, ‘Units’, ‘normalized’, ‘Position’, [0.1, 0.1, 0.8, 0.8]);
tg = uitabgroup(fig,’Units’,’normalized’,"Position",[0,0,1,1]);
t1 = uitab(tg,"Title","Data");
tg1 = uitabgroup(t1,’Units’,’normalized’,"Position",[0,0,1,1]);
t3 = uitab(tg1, ‘Title’, ‘Tab 3’);
t4 = uitab(tg1, ‘Title’, ‘Tab 4’);
t2 = uitab(tg,"Title","Plots");
tg2 = uitabgroup(t2,’Units’,’normalized’,"Position",[0,0,1,1]);
t5 = uitab(tg2, ‘Title’, ‘Tab 5’);
t6 = uitab(tg2, ‘Title’, ‘Tab 6’);
t1.Scrollable = "on";
t2.Scrollable = "on"; plot MATLAB Answers — New Questions
Solar PV System connected to IEEE 14 Bus System
Hi, do anyone know how can i connect this Detailed Model of a 100-kW Grid-connected PV Array (https://www.mathworks.com/help/physmod/sps/ug/detailed-model-of-a-100-kw-grid-connected-pv-array.html) to this IEEE 14 bus system model ( https://www.mathworks.com/matlabcentral/fileexchange/80068-ieee-14-bus-system-model?s_tid=srchtitle ) ?Hi, do anyone know how can i connect this Detailed Model of a 100-kW Grid-connected PV Array (https://www.mathworks.com/help/physmod/sps/ug/detailed-model-of-a-100-kw-grid-connected-pv-array.html) to this IEEE 14 bus system model ( https://www.mathworks.com/matlabcentral/fileexchange/80068-ieee-14-bus-system-model?s_tid=srchtitle ) ? Hi, do anyone know how can i connect this Detailed Model of a 100-kW Grid-connected PV Array (https://www.mathworks.com/help/physmod/sps/ug/detailed-model-of-a-100-kw-grid-connected-pv-array.html) to this IEEE 14 bus system model ( https://www.mathworks.com/matlabcentral/fileexchange/80068-ieee-14-bus-system-model?s_tid=srchtitle ) ? solar, photovoltaic, solar pv system, solar photovoltaic system, ieee 14 bus, ieee bus MATLAB Answers — New Questions
Can I use ”PLACE” matlab function to find feedback gain for discrete state space controller?
I am using PLACE function in MATLAB to find feedback gain for continuous system and I am getting desired output. But when I am using PLACE function for discrete system then I am not getting correct feedback gain. Can I use PLACE function for discrete?
If not then suggest me some another way to find feedback gain matrix for discrete system.I am using PLACE function in MATLAB to find feedback gain for continuous system and I am getting desired output. But when I am using PLACE function for discrete system then I am not getting correct feedback gain. Can I use PLACE function for discrete?
If not then suggest me some another way to find feedback gain matrix for discrete system. I am using PLACE function in MATLAB to find feedback gain for continuous system and I am getting desired output. But when I am using PLACE function for discrete system then I am not getting correct feedback gain. Can I use PLACE function for discrete?
If not then suggest me some another way to find feedback gain matrix for discrete system. control, state space MATLAB Answers — New Questions
I don’t know why my Monte Carlo Localization simulation doesn’t work, I’m using the Monte Carlo Localization toolbox
I think it’s a relatively simple tool and I can’t find my error. Here’s the code:
timeStep = 0.1; % Time step (s)
lin_vel = 1; % Linear velocity (m/s)
resolution = 1; % Map resolution (m)
initial_position = [2 10 90]; % [m m degrees]
robot_pose = initial_position;
lidar_res = 0.1; % Lidar resolution (m)
lidar_range = 5.5;
num_beams = 173;
angles = linspace(-pi/2,pi/2,num_beams);
map_matrix = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
% Binary occupancy map matrix
map = binaryOccupancyMap(map_matrix,resolution);
% In order to follow the red path, the robot has to perform the following
% movements:
% – Up for 5 seconds
% – Right for 8 seconds
% – Down for 6 seconds
% – Right for 6 seconds
% – Down for 7 seconds
% – Left for 7 seconds
% – Up for 5 seconds
% – Left for 7 seconds
% – Up for 2 seconds
% Total simulation time: 53 seconds, we’ll simulate for 1 whole minute
totalTime = 60; % Total simulation time (s)
numParticles = 5000; % Initial number of particles
mcl = monteCarloLocalization; % Initialize MCL object
mcl.UseLidarScan = true;
mcl.GlobalLocalization = true;
mcl.ParticleLimits = [500 numParticles];
mcl.UpdateThresholds = [0.2 0.2 0.2];
mcl.ResamplingInterval = 1;
motionModel = odometryMotionModel; % Initialise motion model
motionModel.Noise = [0.05 0.05 0.05 0.05]; % Add motion error
mcl.MotionModel = motionModel;
sensorModel = likelihoodFieldSensorModel;
sensorModel.Map = map;
sensorModel.SensorLimits = [0 lidar_range];
sensorModel.NumBeams = num_beams;
mcl.SensorModel = sensorModel;
% Simulation loop
for t=0:timeStep:totalTime
if t < 5
robot_pose(2) = robot_pose(2) + lin_vel * timeStep;
robot_pose(3) = 90;
elseif (t>=5)&&(t<13)
robot_pose(1) = robot_pose(1) + lin_vel * timeStep;
robot_pose(3) = 0;
elseif (t>=13)&&(t<19)
robot_pose(2) = robot_pose(2) – lin_vel * timeStep;
robot_pose(3) = 270;
elseif (t>=19)&&(t<25)
robot_pose(1) = robot_pose(1) + lin_vel * timeStep;
robot_pose(3) = 0;
elseif (t>=25)&&(t<32)
robot_pose(2) = robot_pose(2) – lin_vel * timeStep;
robot_pose(3) = 270;
elseif (t>=32)&&(t<39)
robot_pose(1) = robot_pose(1) – lin_vel * timeStep;
robot_pose(3) = 180;
elseif (t>=39)&&(t<44)
robot_pose(2) = robot_pose(2) + lin_vel * timeStep;
robot_pose(3) = 90;
elseif (t>=44)&&(t<51)
robot_pose(1) = robot_pose(1) – lin_vel * timeStep;
robot_pose(3) = 180;
elseif (t>=51)&&(t<53)
robot_pose(2) = robot_pose(2) + lin_vel * timeStep;
robot_pose(3) = 90;
else
% Robot stopped
end
% rayIntersection func. works with radians
robot_pose_radians = robot_pose;
robot_pose_radians(1,3) = robot_pose_radians(1,3)*(pi/180);
intersectionPts = rayIntersection(map,robot_pose_radians,angles,lidar_range);
ranges = sqrt((intersectionPts(:,1)-robot_pose(1)).^2+(intersectionPts(:,2)-robot_pose(2)).^2);
scan = lidarScan(ranges,angles);
[isUpdated,estimatedPose,covariance] = mcl(robot_pose,scan);
particles = getParticles(mcl);
% Update particles plot every 2 "seconds"
if mod(t,2) == 0
particles_plot = particles;
end
figure(1)
show(map)
hold on
scatter(particles_plot(:,1),particles_plot(:,2),’b.’)
hold on
scatter(estimatedPose(:,1),estimatedPose(:,2),’ro’)
hold on
scatter(intersectionPts(:,1),intersectionPts(:,2),’r.’)
hold on
scatter(robot_pose(:,1),robot_pose(:,2),’bo’)
hold off
xlim([0 19])
ylim([0 17])
endI think it’s a relatively simple tool and I can’t find my error. Here’s the code:
timeStep = 0.1; % Time step (s)
lin_vel = 1; % Linear velocity (m/s)
resolution = 1; % Map resolution (m)
initial_position = [2 10 90]; % [m m degrees]
robot_pose = initial_position;
lidar_res = 0.1; % Lidar resolution (m)
lidar_range = 5.5;
num_beams = 173;
angles = linspace(-pi/2,pi/2,num_beams);
map_matrix = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
% Binary occupancy map matrix
map = binaryOccupancyMap(map_matrix,resolution);
% In order to follow the red path, the robot has to perform the following
% movements:
% – Up for 5 seconds
% – Right for 8 seconds
% – Down for 6 seconds
% – Right for 6 seconds
% – Down for 7 seconds
% – Left for 7 seconds
% – Up for 5 seconds
% – Left for 7 seconds
% – Up for 2 seconds
% Total simulation time: 53 seconds, we’ll simulate for 1 whole minute
totalTime = 60; % Total simulation time (s)
numParticles = 5000; % Initial number of particles
mcl = monteCarloLocalization; % Initialize MCL object
mcl.UseLidarScan = true;
mcl.GlobalLocalization = true;
mcl.ParticleLimits = [500 numParticles];
mcl.UpdateThresholds = [0.2 0.2 0.2];
mcl.ResamplingInterval = 1;
motionModel = odometryMotionModel; % Initialise motion model
motionModel.Noise = [0.05 0.05 0.05 0.05]; % Add motion error
mcl.MotionModel = motionModel;
sensorModel = likelihoodFieldSensorModel;
sensorModel.Map = map;
sensorModel.SensorLimits = [0 lidar_range];
sensorModel.NumBeams = num_beams;
mcl.SensorModel = sensorModel;
% Simulation loop
for t=0:timeStep:totalTime
if t < 5
robot_pose(2) = robot_pose(2) + lin_vel * timeStep;
robot_pose(3) = 90;
elseif (t>=5)&&(t<13)
robot_pose(1) = robot_pose(1) + lin_vel * timeStep;
robot_pose(3) = 0;
elseif (t>=13)&&(t<19)
robot_pose(2) = robot_pose(2) – lin_vel * timeStep;
robot_pose(3) = 270;
elseif (t>=19)&&(t<25)
robot_pose(1) = robot_pose(1) + lin_vel * timeStep;
robot_pose(3) = 0;
elseif (t>=25)&&(t<32)
robot_pose(2) = robot_pose(2) – lin_vel * timeStep;
robot_pose(3) = 270;
elseif (t>=32)&&(t<39)
robot_pose(1) = robot_pose(1) – lin_vel * timeStep;
robot_pose(3) = 180;
elseif (t>=39)&&(t<44)
robot_pose(2) = robot_pose(2) + lin_vel * timeStep;
robot_pose(3) = 90;
elseif (t>=44)&&(t<51)
robot_pose(1) = robot_pose(1) – lin_vel * timeStep;
robot_pose(3) = 180;
elseif (t>=51)&&(t<53)
robot_pose(2) = robot_pose(2) + lin_vel * timeStep;
robot_pose(3) = 90;
else
% Robot stopped
end
% rayIntersection func. works with radians
robot_pose_radians = robot_pose;
robot_pose_radians(1,3) = robot_pose_radians(1,3)*(pi/180);
intersectionPts = rayIntersection(map,robot_pose_radians,angles,lidar_range);
ranges = sqrt((intersectionPts(:,1)-robot_pose(1)).^2+(intersectionPts(:,2)-robot_pose(2)).^2);
scan = lidarScan(ranges,angles);
[isUpdated,estimatedPose,covariance] = mcl(robot_pose,scan);
particles = getParticles(mcl);
% Update particles plot every 2 "seconds"
if mod(t,2) == 0
particles_plot = particles;
end
figure(1)
show(map)
hold on
scatter(particles_plot(:,1),particles_plot(:,2),’b.’)
hold on
scatter(estimatedPose(:,1),estimatedPose(:,2),’ro’)
hold on
scatter(intersectionPts(:,1),intersectionPts(:,2),’r.’)
hold on
scatter(robot_pose(:,1),robot_pose(:,2),’bo’)
hold off
xlim([0 19])
ylim([0 17])
end I think it’s a relatively simple tool and I can’t find my error. Here’s the code:
timeStep = 0.1; % Time step (s)
lin_vel = 1; % Linear velocity (m/s)
resolution = 1; % Map resolution (m)
initial_position = [2 10 90]; % [m m degrees]
robot_pose = initial_position;
lidar_res = 0.1; % Lidar resolution (m)
lidar_range = 5.5;
num_beams = 173;
angles = linspace(-pi/2,pi/2,num_beams);
map_matrix = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1;
1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
% Binary occupancy map matrix
map = binaryOccupancyMap(map_matrix,resolution);
% In order to follow the red path, the robot has to perform the following
% movements:
% – Up for 5 seconds
% – Right for 8 seconds
% – Down for 6 seconds
% – Right for 6 seconds
% – Down for 7 seconds
% – Left for 7 seconds
% – Up for 5 seconds
% – Left for 7 seconds
% – Up for 2 seconds
% Total simulation time: 53 seconds, we’ll simulate for 1 whole minute
totalTime = 60; % Total simulation time (s)
numParticles = 5000; % Initial number of particles
mcl = monteCarloLocalization; % Initialize MCL object
mcl.UseLidarScan = true;
mcl.GlobalLocalization = true;
mcl.ParticleLimits = [500 numParticles];
mcl.UpdateThresholds = [0.2 0.2 0.2];
mcl.ResamplingInterval = 1;
motionModel = odometryMotionModel; % Initialise motion model
motionModel.Noise = [0.05 0.05 0.05 0.05]; % Add motion error
mcl.MotionModel = motionModel;
sensorModel = likelihoodFieldSensorModel;
sensorModel.Map = map;
sensorModel.SensorLimits = [0 lidar_range];
sensorModel.NumBeams = num_beams;
mcl.SensorModel = sensorModel;
% Simulation loop
for t=0:timeStep:totalTime
if t < 5
robot_pose(2) = robot_pose(2) + lin_vel * timeStep;
robot_pose(3) = 90;
elseif (t>=5)&&(t<13)
robot_pose(1) = robot_pose(1) + lin_vel * timeStep;
robot_pose(3) = 0;
elseif (t>=13)&&(t<19)
robot_pose(2) = robot_pose(2) – lin_vel * timeStep;
robot_pose(3) = 270;
elseif (t>=19)&&(t<25)
robot_pose(1) = robot_pose(1) + lin_vel * timeStep;
robot_pose(3) = 0;
elseif (t>=25)&&(t<32)
robot_pose(2) = robot_pose(2) – lin_vel * timeStep;
robot_pose(3) = 270;
elseif (t>=32)&&(t<39)
robot_pose(1) = robot_pose(1) – lin_vel * timeStep;
robot_pose(3) = 180;
elseif (t>=39)&&(t<44)
robot_pose(2) = robot_pose(2) + lin_vel * timeStep;
robot_pose(3) = 90;
elseif (t>=44)&&(t<51)
robot_pose(1) = robot_pose(1) – lin_vel * timeStep;
robot_pose(3) = 180;
elseif (t>=51)&&(t<53)
robot_pose(2) = robot_pose(2) + lin_vel * timeStep;
robot_pose(3) = 90;
else
% Robot stopped
end
% rayIntersection func. works with radians
robot_pose_radians = robot_pose;
robot_pose_radians(1,3) = robot_pose_radians(1,3)*(pi/180);
intersectionPts = rayIntersection(map,robot_pose_radians,angles,lidar_range);
ranges = sqrt((intersectionPts(:,1)-robot_pose(1)).^2+(intersectionPts(:,2)-robot_pose(2)).^2);
scan = lidarScan(ranges,angles);
[isUpdated,estimatedPose,covariance] = mcl(robot_pose,scan);
particles = getParticles(mcl);
% Update particles plot every 2 "seconds"
if mod(t,2) == 0
particles_plot = particles;
end
figure(1)
show(map)
hold on
scatter(particles_plot(:,1),particles_plot(:,2),’b.’)
hold on
scatter(estimatedPose(:,1),estimatedPose(:,2),’ro’)
hold on
scatter(intersectionPts(:,1),intersectionPts(:,2),’r.’)
hold on
scatter(robot_pose(:,1),robot_pose(:,2),’bo’)
hold off
xlim([0 19])
ylim([0 17])
end monte carlo localization, particle filter, lidar MATLAB Answers — New Questions
Read excel data in Simulink and convert it into an array
I am trying to import data from an excel sheet as an array into Simulink and turn it into an array. I doing it using a matlab function
the function is written as
function data = dataserial(file,range)
%#codegen
data = readmatrix(file,’Sheet1′,range);
I am getting the following error:
Function ‘readmatrix’ not supported for code generation.
I tried looking this up but I am still a bit uncertain on the excact solution.
I just wanted to enquire if anyone has done the same: Importing excel data as an array
Also, I have tried the "From Spreadsheet" block in simulink but it was not working as wellI am trying to import data from an excel sheet as an array into Simulink and turn it into an array. I doing it using a matlab function
the function is written as
function data = dataserial(file,range)
%#codegen
data = readmatrix(file,’Sheet1′,range);
I am getting the following error:
Function ‘readmatrix’ not supported for code generation.
I tried looking this up but I am still a bit uncertain on the excact solution.
I just wanted to enquire if anyone has done the same: Importing excel data as an array
Also, I have tried the "From Spreadsheet" block in simulink but it was not working as well I am trying to import data from an excel sheet as an array into Simulink and turn it into an array. I doing it using a matlab function
the function is written as
function data = dataserial(file,range)
%#codegen
data = readmatrix(file,’Sheet1′,range);
I am getting the following error:
Function ‘readmatrix’ not supported for code generation.
I tried looking this up but I am still a bit uncertain on the excact solution.
I just wanted to enquire if anyone has done the same: Importing excel data as an array
Also, I have tried the "From Spreadsheet" block in simulink but it was not working as well excel, readmatrix MATLAB Answers — New Questions
How to ploting input signal by “Digilent Analog Discovery Pro 3450”
I am currently trying to use a library to interface Analog Discovery with MATLAB. However, I am encountering an issue. I am practicing the Getting Started code from the Digilent toolbox, and there are no problems when using the Analog Discovery 2 (AD2_0) for Blocking Input Stream. However, when using the "Digilent Analog Discovery Pro 3450" (ADP3450_0), the Blocking Input Stream does not work. I have attached the plotted image below.
The plotting keeps getting stuck like the image below. How can I fix this? The code is as follows:
daqreset;
devices = daqlist %list devices
devices.DeviceInfo(1)
%Single Scan
Read data from 2 analog input channels the display data
daqreset;
dq = daq("digilent");
addinput(dq,"ADP3450_0", "ai0" ,’Voltage’);
addinput(dq,"ADP3450_0", "ai1" ,’Voltage’);
ss = read(dq)
%Blocking Input Stream
Read data for 2 analog input channels then plot
daqreset;
dq = daq("digilent");
addinput(dq, "ADP3450_0", "ai0" ,’Voltage’);
addinput(dq, "ADP3450_0", "ai1" ,’Voltage’);
systemRate = 1e8; %100Mhz max frequency for AD2_0
rDiv = uint32(1) % Rate divisor is expected to be integer
rate = systemRate/rDiv;
dq.Rate = rate; % 100Mhz
data = read(dq, 100);
figure(1);
title(‘Blocking Input Stream’);
xlabel(‘Samples’);
ylabel(‘Volts’);
plot([data.ADP3450_0_ai0, data.ADP3450_0_ai1]);I am currently trying to use a library to interface Analog Discovery with MATLAB. However, I am encountering an issue. I am practicing the Getting Started code from the Digilent toolbox, and there are no problems when using the Analog Discovery 2 (AD2_0) for Blocking Input Stream. However, when using the "Digilent Analog Discovery Pro 3450" (ADP3450_0), the Blocking Input Stream does not work. I have attached the plotted image below.
The plotting keeps getting stuck like the image below. How can I fix this? The code is as follows:
daqreset;
devices = daqlist %list devices
devices.DeviceInfo(1)
%Single Scan
Read data from 2 analog input channels the display data
daqreset;
dq = daq("digilent");
addinput(dq,"ADP3450_0", "ai0" ,’Voltage’);
addinput(dq,"ADP3450_0", "ai1" ,’Voltage’);
ss = read(dq)
%Blocking Input Stream
Read data for 2 analog input channels then plot
daqreset;
dq = daq("digilent");
addinput(dq, "ADP3450_0", "ai0" ,’Voltage’);
addinput(dq, "ADP3450_0", "ai1" ,’Voltage’);
systemRate = 1e8; %100Mhz max frequency for AD2_0
rDiv = uint32(1) % Rate divisor is expected to be integer
rate = systemRate/rDiv;
dq.Rate = rate; % 100Mhz
data = read(dq, 100);
figure(1);
title(‘Blocking Input Stream’);
xlabel(‘Samples’);
ylabel(‘Volts’);
plot([data.ADP3450_0_ai0, data.ADP3450_0_ai1]); I am currently trying to use a library to interface Analog Discovery with MATLAB. However, I am encountering an issue. I am practicing the Getting Started code from the Digilent toolbox, and there are no problems when using the Analog Discovery 2 (AD2_0) for Blocking Input Stream. However, when using the "Digilent Analog Discovery Pro 3450" (ADP3450_0), the Blocking Input Stream does not work. I have attached the plotted image below.
The plotting keeps getting stuck like the image below. How can I fix this? The code is as follows:
daqreset;
devices = daqlist %list devices
devices.DeviceInfo(1)
%Single Scan
Read data from 2 analog input channels the display data
daqreset;
dq = daq("digilent");
addinput(dq,"ADP3450_0", "ai0" ,’Voltage’);
addinput(dq,"ADP3450_0", "ai1" ,’Voltage’);
ss = read(dq)
%Blocking Input Stream
Read data for 2 analog input channels then plot
daqreset;
dq = daq("digilent");
addinput(dq, "ADP3450_0", "ai0" ,’Voltage’);
addinput(dq, "ADP3450_0", "ai1" ,’Voltage’);
systemRate = 1e8; %100Mhz max frequency for AD2_0
rDiv = uint32(1) % Rate divisor is expected to be integer
rate = systemRate/rDiv;
dq.Rate = rate; % 100Mhz
data = read(dq, 100);
figure(1);
title(‘Blocking Input Stream’);
xlabel(‘Samples’);
ylabel(‘Volts’);
plot([data.ADP3450_0_ai0, data.ADP3450_0_ai1]); digilent, data acquisition MATLAB Answers — New Questions
Optimization of EPANET network using GA toolkit
A pipe network distribution layout for irrigation purpose is prepared in EPANET. This network have 80 pipes and 80 nodes plus one reservoir Optimisation of pipe network for minimum cost is required to be done using GA tool box of MATLAB.
The pipe network (EPANET file i.e .inp file) needs to be coupled with MATLAB. And then the same network needs to be optimised. That means diameters of all 80 pipes need to be determined using GA tool box of MATLAB, such that it that will suffice the limiting conditions of design viz: minimum pressure head at outlet nodes must be at least 1 m and velocity in all pipes must be in between 0.6 and 1.8 m/s.
the set of commercially available diameters and there cost is available, need to use those diameters only.A pipe network distribution layout for irrigation purpose is prepared in EPANET. This network have 80 pipes and 80 nodes plus one reservoir Optimisation of pipe network for minimum cost is required to be done using GA tool box of MATLAB.
The pipe network (EPANET file i.e .inp file) needs to be coupled with MATLAB. And then the same network needs to be optimised. That means diameters of all 80 pipes need to be determined using GA tool box of MATLAB, such that it that will suffice the limiting conditions of design viz: minimum pressure head at outlet nodes must be at least 1 m and velocity in all pipes must be in between 0.6 and 1.8 m/s.
the set of commercially available diameters and there cost is available, need to use those diameters only. A pipe network distribution layout for irrigation purpose is prepared in EPANET. This network have 80 pipes and 80 nodes plus one reservoir Optimisation of pipe network for minimum cost is required to be done using GA tool box of MATLAB.
The pipe network (EPANET file i.e .inp file) needs to be coupled with MATLAB. And then the same network needs to be optimised. That means diameters of all 80 pipes need to be determined using GA tool box of MATLAB, such that it that will suffice the limiting conditions of design viz: minimum pressure head at outlet nodes must be at least 1 m and velocity in all pipes must be in between 0.6 and 1.8 m/s.
the set of commercially available diameters and there cost is available, need to use those diameters only. epanet-matlab toolkit, optimization using ga toolkit MATLAB Answers — New Questions
Difference between hist and imhist
Hi,
I have a fundamental question about the hist and imhist and an explanation will be great as I am a bit lost.
I am running this script:
I = imread(‘pout.tif’);
figure;
x=imhist(I)
imhist(I)
figure(2);
hist(x)
and when I compare the two histograms they do not look alike, why?
How can I save the imhist data so that the hist will show the same plot?
ThanksHi,
I have a fundamental question about the hist and imhist and an explanation will be great as I am a bit lost.
I am running this script:
I = imread(‘pout.tif’);
figure;
x=imhist(I)
imhist(I)
figure(2);
hist(x)
and when I compare the two histograms they do not look alike, why?
How can I save the imhist data so that the hist will show the same plot?
Thanks Hi,
I have a fundamental question about the hist and imhist and an explanation will be great as I am a bit lost.
I am running this script:
I = imread(‘pout.tif’);
figure;
x=imhist(I)
imhist(I)
figure(2);
hist(x)
and when I compare the two histograms they do not look alike, why?
How can I save the imhist data so that the hist will show the same plot?
Thanks hist, imhist MATLAB Answers — New Questions
Paramter optimization by curve fitting
I tried paramter optimization by curve fitting. I have five paramters to optimize. If possible, I would kindly like to know the below things.
I kindly would like to know, how opts could be chnaged to have good fit? I have this code. It says options are not excecuted but doesn’t give an error.
How to decide lower and upper bounds?Is it soley based on literature?(In my case, I have only one literature similar to my material, but it didnt give a good fit)
Main file
%rng default % For reproducibility
% Constants
AD = 1.2; % Air density
p0 = 101320; % Air pressure
SH = 1.4; % Specific heat of air
PN = 0.7; % Prandtl constant
c0 = 343; % Air velocity
d = 0.05; % Assuming a constant value for d
% Define the model equation
SAC_fun = @(x, f) your_ATTENBOROUGH_function(x, f, AD, p0, SH, PN, c0, d);
% Load experimental data from Excel file
exp_data = readmatrix(‘/Users/pramodya/Desktop/PhD/Modelling/MATLAB Final codes/My research/Exp.results/Done/C-1.xlsx’); % Assuming first column contains frequencies and second column contains corresponding SAC values
f = exp_data(:, 1); % Frequency data
ydata = exp_data(:, 2); % SAC experimental data
% Plot the experimental data
figure
plot(f, ydata, ‘r*’)
xlabel ‘Frequency’
ylabel ‘SAC’
title(‘Experimental Data’)
% Define the objective function for GA
objectiveFunction = @(x) sum((SAC_fun(x, f) – ydata).^2);
% Define bounds
lb = [0, 0, 0, 0.1]; % Lower bounds for parameters
ub = [2,20, 1e8, 1]; % Upper bounds for parameters
% Define GA options with a specified number of generations
opts = optimoptions(@ga,’SelectionFcn’,@selectiontournament, …
‘FitnessScalingFcn’,@fitscalingprop);
% Run GA to fit the model to the data
nvars = 4; % Number of variables to optimize
[sol, fval] = ga(objectiveFunction, nvars, [], [], [], [], lb, ub, [], options);
% Plot the fitted curve
figure
responsedata = SAC_fun(sol, f);
plot(f, ydata, ‘y*’, f, responsedata, ‘g-‘)
legend(‘Experimental Data’, ‘Fitted Curve’)
xlabel ‘Frequency’
ylabel ‘SAC’
title(‘Fitted Response’)
% Display optimized parameter values
disp(‘Optimized Parameter Values:’);
disp([‘b: ‘, num2str(sol(1))]);
disp([‘T: ‘, num2str(sol(2))]);
disp([‘FR: ‘, num2str(sol(3))]);
disp([‘P: ‘, num2str(sol(4))]);
% Calculate R-squared value
SS_total = sum((ydata – mean(ydata)).^2);
SS_residual = sum((ydata – responsedata).^2);
R_squared = 1 – (SS_residual / SS_total);
% Display R-squared value
disp([‘R-squared Value: ‘, num2str(R_squared)]);
Function file:
function SAC = your_ATTENBOROUGH_function(x, f, AD, p0, SH, PN, c0, d)
% Parameters
%VL = x(1);
b = x(1);%shape factor
T = x(2);
FR = x(3);
P = x(4);
% SAC calculation based on provided equations
s = (1/2*b)*sqrt((8*T*AD*2*pi*f)/(FR*P));
T_bes = besselj(1, s*sqrt(-1i)) ./ besselj(0, s*sqrt(-1i));
p = (T*AD/P) * (1 – (2./(s*sqrt(-1i))) .* T_bes).^-1;
T_bes2 = besselj(1, PN^0.5*s*sqrt(-1i)) ./ besselj(0, PN^0.5*s*sqrt(-1i));
K_w = (SH*p0/P) * (SH – ((2*(SH-1))./(PN^0.5*s*sqrt(-1i))) .* T_bes).^-1;
%Characteristic Impedance
Zc = sqrt(K_w.* p);
%Complex wave number
k_c = 2 * pi * f .* sqrt(p./K_w);
%Surface impedance of sample
Zs = -1i * Zc .* cot(k_c * d);
z0 = AD * c0;
%Normalised impedance
Zn = Zs / z0;
%Reflection coefficient
R = (Zs – z0) ./ (Zs + z0);
%Absorption coefficient
SAC = 1 – abs(R).^2;
end
Thank you in advance.I tried paramter optimization by curve fitting. I have five paramters to optimize. If possible, I would kindly like to know the below things.
I kindly would like to know, how opts could be chnaged to have good fit? I have this code. It says options are not excecuted but doesn’t give an error.
How to decide lower and upper bounds?Is it soley based on literature?(In my case, I have only one literature similar to my material, but it didnt give a good fit)
Main file
%rng default % For reproducibility
% Constants
AD = 1.2; % Air density
p0 = 101320; % Air pressure
SH = 1.4; % Specific heat of air
PN = 0.7; % Prandtl constant
c0 = 343; % Air velocity
d = 0.05; % Assuming a constant value for d
% Define the model equation
SAC_fun = @(x, f) your_ATTENBOROUGH_function(x, f, AD, p0, SH, PN, c0, d);
% Load experimental data from Excel file
exp_data = readmatrix(‘/Users/pramodya/Desktop/PhD/Modelling/MATLAB Final codes/My research/Exp.results/Done/C-1.xlsx’); % Assuming first column contains frequencies and second column contains corresponding SAC values
f = exp_data(:, 1); % Frequency data
ydata = exp_data(:, 2); % SAC experimental data
% Plot the experimental data
figure
plot(f, ydata, ‘r*’)
xlabel ‘Frequency’
ylabel ‘SAC’
title(‘Experimental Data’)
% Define the objective function for GA
objectiveFunction = @(x) sum((SAC_fun(x, f) – ydata).^2);
% Define bounds
lb = [0, 0, 0, 0.1]; % Lower bounds for parameters
ub = [2,20, 1e8, 1]; % Upper bounds for parameters
% Define GA options with a specified number of generations
opts = optimoptions(@ga,’SelectionFcn’,@selectiontournament, …
‘FitnessScalingFcn’,@fitscalingprop);
% Run GA to fit the model to the data
nvars = 4; % Number of variables to optimize
[sol, fval] = ga(objectiveFunction, nvars, [], [], [], [], lb, ub, [], options);
% Plot the fitted curve
figure
responsedata = SAC_fun(sol, f);
plot(f, ydata, ‘y*’, f, responsedata, ‘g-‘)
legend(‘Experimental Data’, ‘Fitted Curve’)
xlabel ‘Frequency’
ylabel ‘SAC’
title(‘Fitted Response’)
% Display optimized parameter values
disp(‘Optimized Parameter Values:’);
disp([‘b: ‘, num2str(sol(1))]);
disp([‘T: ‘, num2str(sol(2))]);
disp([‘FR: ‘, num2str(sol(3))]);
disp([‘P: ‘, num2str(sol(4))]);
% Calculate R-squared value
SS_total = sum((ydata – mean(ydata)).^2);
SS_residual = sum((ydata – responsedata).^2);
R_squared = 1 – (SS_residual / SS_total);
% Display R-squared value
disp([‘R-squared Value: ‘, num2str(R_squared)]);
Function file:
function SAC = your_ATTENBOROUGH_function(x, f, AD, p0, SH, PN, c0, d)
% Parameters
%VL = x(1);
b = x(1);%shape factor
T = x(2);
FR = x(3);
P = x(4);
% SAC calculation based on provided equations
s = (1/2*b)*sqrt((8*T*AD*2*pi*f)/(FR*P));
T_bes = besselj(1, s*sqrt(-1i)) ./ besselj(0, s*sqrt(-1i));
p = (T*AD/P) * (1 – (2./(s*sqrt(-1i))) .* T_bes).^-1;
T_bes2 = besselj(1, PN^0.5*s*sqrt(-1i)) ./ besselj(0, PN^0.5*s*sqrt(-1i));
K_w = (SH*p0/P) * (SH – ((2*(SH-1))./(PN^0.5*s*sqrt(-1i))) .* T_bes).^-1;
%Characteristic Impedance
Zc = sqrt(K_w.* p);
%Complex wave number
k_c = 2 * pi * f .* sqrt(p./K_w);
%Surface impedance of sample
Zs = -1i * Zc .* cot(k_c * d);
z0 = AD * c0;
%Normalised impedance
Zn = Zs / z0;
%Reflection coefficient
R = (Zs – z0) ./ (Zs + z0);
%Absorption coefficient
SAC = 1 – abs(R).^2;
end
Thank you in advance. I tried paramter optimization by curve fitting. I have five paramters to optimize. If possible, I would kindly like to know the below things.
I kindly would like to know, how opts could be chnaged to have good fit? I have this code. It says options are not excecuted but doesn’t give an error.
How to decide lower and upper bounds?Is it soley based on literature?(In my case, I have only one literature similar to my material, but it didnt give a good fit)
Main file
%rng default % For reproducibility
% Constants
AD = 1.2; % Air density
p0 = 101320; % Air pressure
SH = 1.4; % Specific heat of air
PN = 0.7; % Prandtl constant
c0 = 343; % Air velocity
d = 0.05; % Assuming a constant value for d
% Define the model equation
SAC_fun = @(x, f) your_ATTENBOROUGH_function(x, f, AD, p0, SH, PN, c0, d);
% Load experimental data from Excel file
exp_data = readmatrix(‘/Users/pramodya/Desktop/PhD/Modelling/MATLAB Final codes/My research/Exp.results/Done/C-1.xlsx’); % Assuming first column contains frequencies and second column contains corresponding SAC values
f = exp_data(:, 1); % Frequency data
ydata = exp_data(:, 2); % SAC experimental data
% Plot the experimental data
figure
plot(f, ydata, ‘r*’)
xlabel ‘Frequency’
ylabel ‘SAC’
title(‘Experimental Data’)
% Define the objective function for GA
objectiveFunction = @(x) sum((SAC_fun(x, f) – ydata).^2);
% Define bounds
lb = [0, 0, 0, 0.1]; % Lower bounds for parameters
ub = [2,20, 1e8, 1]; % Upper bounds for parameters
% Define GA options with a specified number of generations
opts = optimoptions(@ga,’SelectionFcn’,@selectiontournament, …
‘FitnessScalingFcn’,@fitscalingprop);
% Run GA to fit the model to the data
nvars = 4; % Number of variables to optimize
[sol, fval] = ga(objectiveFunction, nvars, [], [], [], [], lb, ub, [], options);
% Plot the fitted curve
figure
responsedata = SAC_fun(sol, f);
plot(f, ydata, ‘y*’, f, responsedata, ‘g-‘)
legend(‘Experimental Data’, ‘Fitted Curve’)
xlabel ‘Frequency’
ylabel ‘SAC’
title(‘Fitted Response’)
% Display optimized parameter values
disp(‘Optimized Parameter Values:’);
disp([‘b: ‘, num2str(sol(1))]);
disp([‘T: ‘, num2str(sol(2))]);
disp([‘FR: ‘, num2str(sol(3))]);
disp([‘P: ‘, num2str(sol(4))]);
% Calculate R-squared value
SS_total = sum((ydata – mean(ydata)).^2);
SS_residual = sum((ydata – responsedata).^2);
R_squared = 1 – (SS_residual / SS_total);
% Display R-squared value
disp([‘R-squared Value: ‘, num2str(R_squared)]);
Function file:
function SAC = your_ATTENBOROUGH_function(x, f, AD, p0, SH, PN, c0, d)
% Parameters
%VL = x(1);
b = x(1);%shape factor
T = x(2);
FR = x(3);
P = x(4);
% SAC calculation based on provided equations
s = (1/2*b)*sqrt((8*T*AD*2*pi*f)/(FR*P));
T_bes = besselj(1, s*sqrt(-1i)) ./ besselj(0, s*sqrt(-1i));
p = (T*AD/P) * (1 – (2./(s*sqrt(-1i))) .* T_bes).^-1;
T_bes2 = besselj(1, PN^0.5*s*sqrt(-1i)) ./ besselj(0, PN^0.5*s*sqrt(-1i));
K_w = (SH*p0/P) * (SH – ((2*(SH-1))./(PN^0.5*s*sqrt(-1i))) .* T_bes).^-1;
%Characteristic Impedance
Zc = sqrt(K_w.* p);
%Complex wave number
k_c = 2 * pi * f .* sqrt(p./K_w);
%Surface impedance of sample
Zs = -1i * Zc .* cot(k_c * d);
z0 = AD * c0;
%Normalised impedance
Zn = Zs / z0;
%Reflection coefficient
R = (Zs – z0) ./ (Zs + z0);
%Absorption coefficient
SAC = 1 – abs(R).^2;
end
Thank you in advance. paramter optimizaiton, ga, curve fitting MATLAB Answers — New Questions
How can I download MATLAB & Simulink R2013a student version without cd?
How can I download MATLAB & Simulink R2013a student version without cd? I bought a new computer without an optical drive, so I cannot download MATLAB using the installation disc that came when I purchased the software. Just wondering how I could download the software for a mac (I already have a key code for authorization)?How can I download MATLAB & Simulink R2013a student version without cd? I bought a new computer without an optical drive, so I cannot download MATLAB using the installation disc that came when I purchased the software. Just wondering how I could download the software for a mac (I already have a key code for authorization)? How can I download MATLAB & Simulink R2013a student version without cd? I bought a new computer without an optical drive, so I cannot download MATLAB using the installation disc that came when I purchased the software. Just wondering how I could download the software for a mac (I already have a key code for authorization)? software, download, version upgrade MATLAB Answers — New Questions
Can I use splitapply with two grouping variables and how can it be done in matlab app designer?
Hi ! 🙂
I am referring to this example:
load carsmall
whos
Name Size Bytes Class Attributes
Acceleration 100×1 800 double
Cylinders 100×1 800 double
Displacement 100×1 800 double
Horsepower 100×1 800 double
MPG 100×1 800 double
Mfg 100×13 2600 char
Model 100×33 6600 char
Model_Year 100×1 800 double
Origin 100×7 1400 char
Weight 100×1 800 double
cmdout 1×33 66 char
[g,id]=findgroups(Model_Year);
hAx=axes; hold(hAx,’on’)
splitapply(@(x,y)scatter(x,y,’filled’),Displacement,Horsepower,g)
legend(hAx,"Model Year "+string(1900+id),’location’,’northwest’)
xlabel(‘Displacement’), ylabel(‘Horsepower’)
——————————–
I have a table which is heterogenous. And I want to show the names of the first preferred salt user has chosen and second preferred salt (these are two of the column in my table) along with their properties on the x and y axis. Their properties are also the different columns in my tableHi ! 🙂
I am referring to this example:
load carsmall
whos
Name Size Bytes Class Attributes
Acceleration 100×1 800 double
Cylinders 100×1 800 double
Displacement 100×1 800 double
Horsepower 100×1 800 double
MPG 100×1 800 double
Mfg 100×13 2600 char
Model 100×33 6600 char
Model_Year 100×1 800 double
Origin 100×7 1400 char
Weight 100×1 800 double
cmdout 1×33 66 char
[g,id]=findgroups(Model_Year);
hAx=axes; hold(hAx,’on’)
splitapply(@(x,y)scatter(x,y,’filled’),Displacement,Horsepower,g)
legend(hAx,"Model Year "+string(1900+id),’location’,’northwest’)
xlabel(‘Displacement’), ylabel(‘Horsepower’)
——————————–
I have a table which is heterogenous. And I want to show the names of the first preferred salt user has chosen and second preferred salt (these are two of the column in my table) along with their properties on the x and y axis. Their properties are also the different columns in my table Hi ! 🙂
I am referring to this example:
load carsmall
whos
Name Size Bytes Class Attributes
Acceleration 100×1 800 double
Cylinders 100×1 800 double
Displacement 100×1 800 double
Horsepower 100×1 800 double
MPG 100×1 800 double
Mfg 100×13 2600 char
Model 100×33 6600 char
Model_Year 100×1 800 double
Origin 100×7 1400 char
Weight 100×1 800 double
cmdout 1×33 66 char
[g,id]=findgroups(Model_Year);
hAx=axes; hold(hAx,’on’)
splitapply(@(x,y)scatter(x,y,’filled’),Displacement,Horsepower,g)
legend(hAx,"Model Year "+string(1900+id),’location’,’northwest’)
xlabel(‘Displacement’), ylabel(‘Horsepower’)
——————————–
I have a table which is heterogenous. And I want to show the names of the first preferred salt user has chosen and second preferred salt (these are two of the column in my table) along with their properties on the x and y axis. Their properties are also the different columns in my table matlab app designer, split apply, two grouping variables MATLAB Answers — New Questions
simulink -sinx integral
As I know, integral -sinx dx is cosx
but, in sinulink there is offset !As I know, integral -sinx dx is cosx
but, in sinulink there is offset ! As I know, integral -sinx dx is cosx
but, in sinulink there is offset ! simulink MATLAB Answers — New Questions
I’m trying to solve two separate systems using ODE23 while controlling the number of indexes so that the indexes are equal for both systems, but I couldn’t. Can you help? Than
function [sol1,sol2] = two_system
clc
close all
clear all
opt = odeset(‘RelTol’,1e-3);
sol1 = ode23(@system1,[0 5],[0],opt);
sol2 = ode23(@system2,[0 5],[0],opt);
figure(1)
plot(sol1.x(1,:),sol1.y(1,:),’b’,’LineWidth’,1.5)
hold on
plot(sol2.x(1,:),sol2.y(1,:),’–r’,’LineWidth’,1.5)
L1=length(sol1.x(1,:))
L2=length(sol2.x(1,:))
end
function dydt = system1(t,y)
M1 = y(1);
F_M1= 2;
theta1=0*pi/180;
A1 = 0.01;
%%%%%%% equation_system1 %%%%%%%
dMdt=(A1*(2*pi*(F_M1))*cos(2*pi*(F_M1)*(t)+theta1));
dydt = [dMdt];
end
function dydt = system2(t,y)
M2 = y(1);
F_M2= 2;
theta2=90*pi/180;
A2 = 0.01;
%%%%%%% equation_system2 %%%%%%%
dMdt=(A2*(2*pi*(F_M2))*cos(2*pi*(F_M2)*(t)+theta2));
dydt = [dMdt];
endfunction [sol1,sol2] = two_system
clc
close all
clear all
opt = odeset(‘RelTol’,1e-3);
sol1 = ode23(@system1,[0 5],[0],opt);
sol2 = ode23(@system2,[0 5],[0],opt);
figure(1)
plot(sol1.x(1,:),sol1.y(1,:),’b’,’LineWidth’,1.5)
hold on
plot(sol2.x(1,:),sol2.y(1,:),’–r’,’LineWidth’,1.5)
L1=length(sol1.x(1,:))
L2=length(sol2.x(1,:))
end
function dydt = system1(t,y)
M1 = y(1);
F_M1= 2;
theta1=0*pi/180;
A1 = 0.01;
%%%%%%% equation_system1 %%%%%%%
dMdt=(A1*(2*pi*(F_M1))*cos(2*pi*(F_M1)*(t)+theta1));
dydt = [dMdt];
end
function dydt = system2(t,y)
M2 = y(1);
F_M2= 2;
theta2=90*pi/180;
A2 = 0.01;
%%%%%%% equation_system2 %%%%%%%
dMdt=(A2*(2*pi*(F_M2))*cos(2*pi*(F_M2)*(t)+theta2));
dydt = [dMdt];
end function [sol1,sol2] = two_system
clc
close all
clear all
opt = odeset(‘RelTol’,1e-3);
sol1 = ode23(@system1,[0 5],[0],opt);
sol2 = ode23(@system2,[0 5],[0],opt);
figure(1)
plot(sol1.x(1,:),sol1.y(1,:),’b’,’LineWidth’,1.5)
hold on
plot(sol2.x(1,:),sol2.y(1,:),’–r’,’LineWidth’,1.5)
L1=length(sol1.x(1,:))
L2=length(sol2.x(1,:))
end
function dydt = system1(t,y)
M1 = y(1);
F_M1= 2;
theta1=0*pi/180;
A1 = 0.01;
%%%%%%% equation_system1 %%%%%%%
dMdt=(A1*(2*pi*(F_M1))*cos(2*pi*(F_M1)*(t)+theta1));
dydt = [dMdt];
end
function dydt = system2(t,y)
M2 = y(1);
F_M2= 2;
theta2=90*pi/180;
A2 = 0.01;
%%%%%%% equation_system2 %%%%%%%
dMdt=(A2*(2*pi*(F_M2))*cos(2*pi*(F_M2)*(t)+theta2));
dydt = [dMdt];
end mischa kim MATLAB Answers — New Questions
Simulate Fick’s 1st and 2nd laws of mass diffusion.
Dear a person who is looking this.
I am trying to simulate the mass diffusion based on Fick’s laws on 2D plane.
The initial condition is that the concentration on the left wall is 1.
But the result seems to be odd as below.
I guess the problem is from the code for the 2nd law. So I have tried to modify that like
C(i,j) = C(i,j) …
– dt * ((Jx(i, j) – Jx(i-1,j))/(dx) …
+ (Jy(i, j) – Jy(i,j-1))/(dy));
But the result was the same.
How can I solve this problem. I really want some help..
Thank you for reading this.
======Here is my code (you can operate by just copy and paste)=======
% Parameters
Nx = 20; % Number of grid points in x-direction
Ny = 20; % Number of grid points in y-direction
D = 0.1; % Diffusion coefficient
dx = 1.0; % Spatial step in x-direction
dy = 1.0; % Spatial step in y-direction
dt = 0.1; % Time step
T = 200.0; % Total simulation time
C = zeros(Nx, Ny); % Initial concentration
Jx = zeros(Nx, Ny);
Jy = zeros(Nx, Ny);
C(:, 1) = 1.0; % Initial condition: concentrated mass at the center
% Time loop
for t = 0:dt:T
% Create a copy of the concentration array to hold the new values
% C_new = C;
% Iterate over each interior point
% flux
% Fick’s 1st law: J = -D * del c
for i = 2:Nx-1
for j = 2:Ny-1
Jx(i,j) = – D * (C(i,j) – C(i-1,j))/dx – D * (C(i+1,j) – C(i,j))/dx ;
Jy(i,j) = – D * (C(i,j) – C(i,j-1))/dy – D * (C(i,j+1) – C(i,j))/dy ;
end
end
% concentration
% Fick’s 2nd law: partial dc/dt = – div J
for i = 2:Nx-1
for j = 2:Ny-1
C(i,j) = C(i,j) …
– dt * ((Jx(i+1, j) – Jx(i-1,j))/(2*dx) …
+ (Jy(i, j+1) – Jy(i,j-1))/(2*dy));
end
end
% Optionally plot the concentration at each time step
slice_view = squeeze(C(:,:)); % View a slice in the middle of the z-plane
imagesc(slice_view);
colorbar;
colormap(‘jet’);
title(sprintf(‘Time = %.2f’, t));
drawnow;
end
% Final plot
slice_view = squeeze(C(:,:)); % View a slice in the middle of the z-plane
imagesc(slice_view);
colorbar;
title(‘Final Concentration’);
xlabel(‘X’);
ylabel(‘Y’);Dear a person who is looking this.
I am trying to simulate the mass diffusion based on Fick’s laws on 2D plane.
The initial condition is that the concentration on the left wall is 1.
But the result seems to be odd as below.
I guess the problem is from the code for the 2nd law. So I have tried to modify that like
C(i,j) = C(i,j) …
– dt * ((Jx(i, j) – Jx(i-1,j))/(dx) …
+ (Jy(i, j) – Jy(i,j-1))/(dy));
But the result was the same.
How can I solve this problem. I really want some help..
Thank you for reading this.
======Here is my code (you can operate by just copy and paste)=======
% Parameters
Nx = 20; % Number of grid points in x-direction
Ny = 20; % Number of grid points in y-direction
D = 0.1; % Diffusion coefficient
dx = 1.0; % Spatial step in x-direction
dy = 1.0; % Spatial step in y-direction
dt = 0.1; % Time step
T = 200.0; % Total simulation time
C = zeros(Nx, Ny); % Initial concentration
Jx = zeros(Nx, Ny);
Jy = zeros(Nx, Ny);
C(:, 1) = 1.0; % Initial condition: concentrated mass at the center
% Time loop
for t = 0:dt:T
% Create a copy of the concentration array to hold the new values
% C_new = C;
% Iterate over each interior point
% flux
% Fick’s 1st law: J = -D * del c
for i = 2:Nx-1
for j = 2:Ny-1
Jx(i,j) = – D * (C(i,j) – C(i-1,j))/dx – D * (C(i+1,j) – C(i,j))/dx ;
Jy(i,j) = – D * (C(i,j) – C(i,j-1))/dy – D * (C(i,j+1) – C(i,j))/dy ;
end
end
% concentration
% Fick’s 2nd law: partial dc/dt = – div J
for i = 2:Nx-1
for j = 2:Ny-1
C(i,j) = C(i,j) …
– dt * ((Jx(i+1, j) – Jx(i-1,j))/(2*dx) …
+ (Jy(i, j+1) – Jy(i,j-1))/(2*dy));
end
end
% Optionally plot the concentration at each time step
slice_view = squeeze(C(:,:)); % View a slice in the middle of the z-plane
imagesc(slice_view);
colorbar;
colormap(‘jet’);
title(sprintf(‘Time = %.2f’, t));
drawnow;
end
% Final plot
slice_view = squeeze(C(:,:)); % View a slice in the middle of the z-plane
imagesc(slice_view);
colorbar;
title(‘Final Concentration’);
xlabel(‘X’);
ylabel(‘Y’); Dear a person who is looking this.
I am trying to simulate the mass diffusion based on Fick’s laws on 2D plane.
The initial condition is that the concentration on the left wall is 1.
But the result seems to be odd as below.
I guess the problem is from the code for the 2nd law. So I have tried to modify that like
C(i,j) = C(i,j) …
– dt * ((Jx(i, j) – Jx(i-1,j))/(dx) …
+ (Jy(i, j) – Jy(i,j-1))/(dy));
But the result was the same.
How can I solve this problem. I really want some help..
Thank you for reading this.
======Here is my code (you can operate by just copy and paste)=======
% Parameters
Nx = 20; % Number of grid points in x-direction
Ny = 20; % Number of grid points in y-direction
D = 0.1; % Diffusion coefficient
dx = 1.0; % Spatial step in x-direction
dy = 1.0; % Spatial step in y-direction
dt = 0.1; % Time step
T = 200.0; % Total simulation time
C = zeros(Nx, Ny); % Initial concentration
Jx = zeros(Nx, Ny);
Jy = zeros(Nx, Ny);
C(:, 1) = 1.0; % Initial condition: concentrated mass at the center
% Time loop
for t = 0:dt:T
% Create a copy of the concentration array to hold the new values
% C_new = C;
% Iterate over each interior point
% flux
% Fick’s 1st law: J = -D * del c
for i = 2:Nx-1
for j = 2:Ny-1
Jx(i,j) = – D * (C(i,j) – C(i-1,j))/dx – D * (C(i+1,j) – C(i,j))/dx ;
Jy(i,j) = – D * (C(i,j) – C(i,j-1))/dy – D * (C(i,j+1) – C(i,j))/dy ;
end
end
% concentration
% Fick’s 2nd law: partial dc/dt = – div J
for i = 2:Nx-1
for j = 2:Ny-1
C(i,j) = C(i,j) …
– dt * ((Jx(i+1, j) – Jx(i-1,j))/(2*dx) …
+ (Jy(i, j+1) – Jy(i,j-1))/(2*dy));
end
end
% Optionally plot the concentration at each time step
slice_view = squeeze(C(:,:)); % View a slice in the middle of the z-plane
imagesc(slice_view);
colorbar;
colormap(‘jet’);
title(sprintf(‘Time = %.2f’, t));
drawnow;
end
% Final plot
slice_view = squeeze(C(:,:)); % View a slice in the middle of the z-plane
imagesc(slice_view);
colorbar;
title(‘Final Concentration’);
xlabel(‘X’);
ylabel(‘Y’); physics, diffusion, mass diffusion, differential equations MATLAB Answers — New Questions