Category: Matlab
Category Archives: Matlab
Why can’t I call a specified value in a 4D matrix mat-file when the last dimension is larger than 200?
Hi everyone,
I have one variable ‘irf’ sized 2241x5x105x10000 in a mat-file ver 7.3. When I load the mat-file and call the variable it returns all the values.
However, if I call certain specified value for ex irf(a,b,c,d) and d is larger than 200, Matlab always returns the value as 0.
I tried using m=matfile(‘myfile.mat’, ‘Writable’, false) then call m.irf(a,b,c,d) and still the value for d larger than 200 is always 0.
What did I do wrong here? How can I call a specified located value in my variable when d is larger than 200?
I work with Matlab 2024a with 128GB RAM in a virtual machine.
Many thanks in advanceHi everyone,
I have one variable ‘irf’ sized 2241x5x105x10000 in a mat-file ver 7.3. When I load the mat-file and call the variable it returns all the values.
However, if I call certain specified value for ex irf(a,b,c,d) and d is larger than 200, Matlab always returns the value as 0.
I tried using m=matfile(‘myfile.mat’, ‘Writable’, false) then call m.irf(a,b,c,d) and still the value for d larger than 200 is always 0.
What did I do wrong here? How can I call a specified located value in my variable when d is larger than 200?
I work with Matlab 2024a with 128GB RAM in a virtual machine.
Many thanks in advance Hi everyone,
I have one variable ‘irf’ sized 2241x5x105x10000 in a mat-file ver 7.3. When I load the mat-file and call the variable it returns all the values.
However, if I call certain specified value for ex irf(a,b,c,d) and d is larger than 200, Matlab always returns the value as 0.
I tried using m=matfile(‘myfile.mat’, ‘Writable’, false) then call m.irf(a,b,c,d) and still the value for d larger than 200 is always 0.
What did I do wrong here? How can I call a specified located value in my variable when d is larger than 200?
I work with Matlab 2024a with 128GB RAM in a virtual machine.
Many thanks in advance mat-file, large data MATLAB Answers — New Questions
Programmatically adjust the width of Document Bar
I am looking for a way to programatically adjust the width of this panel, does anyone have any ideas?
I am using setDocumentBarPosition to move this panel to the left side onf the window. I would like to adjust it’s width but can’t figure out how. I am able to get it’s current inset value using getGroupContainerInsets but am stuck at trying to figure out how to modify it. there is definitely something that matlab is storing in the background because it remembers the width when i re-create the group in a different instance of matlab.I am looking for a way to programatically adjust the width of this panel, does anyone have any ideas?
I am using setDocumentBarPosition to move this panel to the left side onf the window. I would like to adjust it’s width but can’t figure out how. I am able to get it’s current inset value using getGroupContainerInsets but am stuck at trying to figure out how to modify it. there is definitely something that matlab is storing in the background because it remembers the width when i re-create the group in a different instance of matlab. I am looking for a way to programatically adjust the width of this panel, does anyone have any ideas?
I am using setDocumentBarPosition to move this panel to the left side onf the window. I would like to adjust it’s width but can’t figure out how. I am able to get it’s current inset value using getGroupContainerInsets but am stuck at trying to figure out how to modify it. there is definitely something that matlab is storing in the background because it remembers the width when i re-create the group in a different instance of matlab. jframe, figure, undocumented MATLAB Answers — New Questions
program block diagram in matlab, not simulink
Hi,
I have an task to calculate the transferfunction with an given, complicated block diagram. So I simplify the block diagram until I have the complete transfer function in the last block – not a problem. Now I have the next task which tells me to proof that my previous calculations are correct using matlab (not simulink, which would be the third task; and I have already done that to make sure my transfer function from task a) was correct)
So my question is: how do I translate a block diagram with given transfer functions into matlab code? I can easily define all the blocks’ transfer functions like G1=tf(c1,d1);, but how do I tell matlab in code where a sum is, where a branch splits etc?
I would realy appreciate any help, as that is something our professor does not show in his vids and leaves to our own to figure out -.-
Thank you very much,
DennisHi,
I have an task to calculate the transferfunction with an given, complicated block diagram. So I simplify the block diagram until I have the complete transfer function in the last block – not a problem. Now I have the next task which tells me to proof that my previous calculations are correct using matlab (not simulink, which would be the third task; and I have already done that to make sure my transfer function from task a) was correct)
So my question is: how do I translate a block diagram with given transfer functions into matlab code? I can easily define all the blocks’ transfer functions like G1=tf(c1,d1);, but how do I tell matlab in code where a sum is, where a branch splits etc?
I would realy appreciate any help, as that is something our professor does not show in his vids and leaves to our own to figure out -.-
Thank you very much,
Dennis Hi,
I have an task to calculate the transferfunction with an given, complicated block diagram. So I simplify the block diagram until I have the complete transfer function in the last block – not a problem. Now I have the next task which tells me to proof that my previous calculations are correct using matlab (not simulink, which would be the third task; and I have already done that to make sure my transfer function from task a) was correct)
So my question is: how do I translate a block diagram with given transfer functions into matlab code? I can easily define all the blocks’ transfer functions like G1=tf(c1,d1);, but how do I tell matlab in code where a sum is, where a branch splits etc?
I would realy appreciate any help, as that is something our professor does not show in his vids and leaves to our own to figure out -.-
Thank you very much,
Dennis block diagram, transfer function, matlab MATLAB Answers — New Questions
Correct the code for me please
% Given data points
x = [0,0.1, 0.8, 0.6, 0.9, 1];
f = [-1,-1.2299,-3.455, -2.9949, -3.3929, -3];
% Part (a) – Construct the divided difference table
n = length(x);
d = zeros(n);
d(1,1) = f(1);
for i = 2:n
d(i,1) = (f(i) – f(i-1))/(x(i) – x(i-1));
for j = 2:i
d(i,j) = (d(i,j-1) – d(i-1,j-1))/(x(i) – x(i-j));
end
end
disp(‘Divided Difference Table:’)
disp(d)
% Part (b) – Evaluate the polynomial of order "n-1"
y = 0;
for i = 1:n
temp = f(1);
for j = 1:i
temp = temp * (0.5 – x(1:i-j)) + d(i,j);
end
y = y + temp;
end
fprintf(‘The value of the polynomial at x = 0.5 is %.4fn’, y)
% Part (c) – Evaluate f(0.5)
f_interp = interp1(x,f,0.5);
fprintf(‘The value of f(0.5) is %.4fn’, f_interp)
% Part (d) – Check your answers using built-in MATLAB functions
p = polyfit(x,f,5);
y_polyfit = polyval(p,0.5);
fprintf(‘The value of the polynomial at x = 0.5 using polyfit is %.4fn’, y_polyfit)
f_interp_polyfit = interp1(x,f,0.5,’linear’);
fprintf(‘The value of f(0.5) using interp1 is %.4fn’, f_interp_polyfit)% Given data points
x = [0,0.1, 0.8, 0.6, 0.9, 1];
f = [-1,-1.2299,-3.455, -2.9949, -3.3929, -3];
% Part (a) – Construct the divided difference table
n = length(x);
d = zeros(n);
d(1,1) = f(1);
for i = 2:n
d(i,1) = (f(i) – f(i-1))/(x(i) – x(i-1));
for j = 2:i
d(i,j) = (d(i,j-1) – d(i-1,j-1))/(x(i) – x(i-j));
end
end
disp(‘Divided Difference Table:’)
disp(d)
% Part (b) – Evaluate the polynomial of order "n-1"
y = 0;
for i = 1:n
temp = f(1);
for j = 1:i
temp = temp * (0.5 – x(1:i-j)) + d(i,j);
end
y = y + temp;
end
fprintf(‘The value of the polynomial at x = 0.5 is %.4fn’, y)
% Part (c) – Evaluate f(0.5)
f_interp = interp1(x,f,0.5);
fprintf(‘The value of f(0.5) is %.4fn’, f_interp)
% Part (d) – Check your answers using built-in MATLAB functions
p = polyfit(x,f,5);
y_polyfit = polyval(p,0.5);
fprintf(‘The value of the polynomial at x = 0.5 using polyfit is %.4fn’, y_polyfit)
f_interp_polyfit = interp1(x,f,0.5,’linear’);
fprintf(‘The value of f(0.5) using interp1 is %.4fn’, f_interp_polyfit) % Given data points
x = [0,0.1, 0.8, 0.6, 0.9, 1];
f = [-1,-1.2299,-3.455, -2.9949, -3.3929, -3];
% Part (a) – Construct the divided difference table
n = length(x);
d = zeros(n);
d(1,1) = f(1);
for i = 2:n
d(i,1) = (f(i) – f(i-1))/(x(i) – x(i-1));
for j = 2:i
d(i,j) = (d(i,j-1) – d(i-1,j-1))/(x(i) – x(i-j));
end
end
disp(‘Divided Difference Table:’)
disp(d)
% Part (b) – Evaluate the polynomial of order "n-1"
y = 0;
for i = 1:n
temp = f(1);
for j = 1:i
temp = temp * (0.5 – x(1:i-j)) + d(i,j);
end
y = y + temp;
end
fprintf(‘The value of the polynomial at x = 0.5 is %.4fn’, y)
% Part (c) – Evaluate f(0.5)
f_interp = interp1(x,f,0.5);
fprintf(‘The value of f(0.5) is %.4fn’, f_interp)
% Part (d) – Check your answers using built-in MATLAB functions
p = polyfit(x,f,5);
y_polyfit = polyval(p,0.5);
fprintf(‘The value of the polynomial at x = 0.5 using polyfit is %.4fn’, y_polyfit)
f_interp_polyfit = interp1(x,f,0.5,’linear’);
fprintf(‘The value of f(0.5) using interp1 is %.4fn’, f_interp_polyfit) numerical MATLAB Answers — New Questions
My User-defined Function is in red
I followed the exact format to set up a user-defined function in the first line. Even my classmates’ worked perfectly fine but mine. Can anyone show me why my function is in red?I followed the exact format to set up a user-defined function in the first line. Even my classmates’ worked perfectly fine but mine. Can anyone show me why my function is in red? I followed the exact format to set up a user-defined function in the first line. Even my classmates’ worked perfectly fine but mine. Can anyone show me why my function is in red? user-defined functions MATLAB Answers — New Questions
What is the reason that GoogleNet takes less time than MobileNetv2 and EfficientNet-b0 for feature extraction from a set of images?
I am using 3 Pre-trained networks namely GoogLeNet, MobileNetv2 and EfficientNet-b0 for feature extraction task on a set of images. Time taken (in seconds per frame) by GoogLeNet among these three networks is the least, whereas EfficientNet-b0 took the longest time. MobileNetv2 fell in between these two. In summary, we can show time taken (in seconds per frame) by these networks as following:
GoogLeNet < MobileNetv2 < EfficientNet-b0
I am trying to find a valid reason for this. Can this be attributed to the fact that depth of GoogLeNet is 22, being less than the depth of MobileNetv2 ( 53) and depth of EfficientNet-b0 being 82 ?
Can someone please put some light on this?
I have also gone through the plot shown in the following link that shows that realtive prediction time of GoogLeNet is less than MobileNetv2 which is less than EfficientNet-b0
https://in.mathworks.com/help/deeplearning/ug/pretrained-convolutional-neural-networks.htmlI am using 3 Pre-trained networks namely GoogLeNet, MobileNetv2 and EfficientNet-b0 for feature extraction task on a set of images. Time taken (in seconds per frame) by GoogLeNet among these three networks is the least, whereas EfficientNet-b0 took the longest time. MobileNetv2 fell in between these two. In summary, we can show time taken (in seconds per frame) by these networks as following:
GoogLeNet < MobileNetv2 < EfficientNet-b0
I am trying to find a valid reason for this. Can this be attributed to the fact that depth of GoogLeNet is 22, being less than the depth of MobileNetv2 ( 53) and depth of EfficientNet-b0 being 82 ?
Can someone please put some light on this?
I have also gone through the plot shown in the following link that shows that realtive prediction time of GoogLeNet is less than MobileNetv2 which is less than EfficientNet-b0
https://in.mathworks.com/help/deeplearning/ug/pretrained-convolutional-neural-networks.html I am using 3 Pre-trained networks namely GoogLeNet, MobileNetv2 and EfficientNet-b0 for feature extraction task on a set of images. Time taken (in seconds per frame) by GoogLeNet among these three networks is the least, whereas EfficientNet-b0 took the longest time. MobileNetv2 fell in between these two. In summary, we can show time taken (in seconds per frame) by these networks as following:
GoogLeNet < MobileNetv2 < EfficientNet-b0
I am trying to find a valid reason for this. Can this be attributed to the fact that depth of GoogLeNet is 22, being less than the depth of MobileNetv2 ( 53) and depth of EfficientNet-b0 being 82 ?
Can someone please put some light on this?
I have also gone through the plot shown in the following link that shows that realtive prediction time of GoogLeNet is less than MobileNetv2 which is less than EfficientNet-b0
https://in.mathworks.com/help/deeplearning/ug/pretrained-convolutional-neural-networks.html pre-trained networks, googlenet, mobilenetv2, deep learning, matlab, neural networks, efficientnet-b0 MATLAB Answers — New Questions
Time Scaling In Discrete Time Signals
Hello everyone. I want to apply time scaling property to my signal. It is hard for me to apply for the signals especially like x[4n], x[2n], x[1/3n]. I know there must be mod calculation because the values should be integer but i could not write the code can someone help me please?
n=[-2 -1 0 1 2 3 4];
x=[3 1 0 4 6 2 9];Hello everyone. I want to apply time scaling property to my signal. It is hard for me to apply for the signals especially like x[4n], x[2n], x[1/3n]. I know there must be mod calculation because the values should be integer but i could not write the code can someone help me please?
n=[-2 -1 0 1 2 3 4];
x=[3 1 0 4 6 2 9]; Hello everyone. I want to apply time scaling property to my signal. It is hard for me to apply for the signals especially like x[4n], x[2n], x[1/3n]. I know there must be mod calculation because the values should be integer but i could not write the code can someone help me please?
n=[-2 -1 0 1 2 3 4];
x=[3 1 0 4 6 2 9]; time scaling, discrete time, property, scaling, time, dsp, stem, matlab MATLAB Answers — New Questions
how to change the transparency of individual colors in the colormap of an image?
Hello,
I’m using bubblechart to display my data as shown below;
bubblechart(x2xz,z2xz,ones(size(x2xz)),n2xz,’MarkerFaceAlpha’,0.1,’MarkerEdgeAlpha’,0.2);
-this works. However it would be better if I could make MarkerFaceAlpha a variable, so that it changes based on the value of n2xz (which currently controls the colour of the bubbles). Unfortunately MarkerFaceAlpha has to be a scalar, not a vector, with bubblechart.
The plot command accepts colours in this format (where the fourth column is the transparency); ‘Color’,[0.0 0.0 1.0 0.3], but when I build a colormap with four columns and try to use that instead of using the MarkerFaceAlpha option, the colormap command rejects it.
I have googled this and searched Matlab Answers, but nothing useful was found.
Any suggestions would be gratefully received. Thank you.
Gordon CooperHello,
I’m using bubblechart to display my data as shown below;
bubblechart(x2xz,z2xz,ones(size(x2xz)),n2xz,’MarkerFaceAlpha’,0.1,’MarkerEdgeAlpha’,0.2);
-this works. However it would be better if I could make MarkerFaceAlpha a variable, so that it changes based on the value of n2xz (which currently controls the colour of the bubbles). Unfortunately MarkerFaceAlpha has to be a scalar, not a vector, with bubblechart.
The plot command accepts colours in this format (where the fourth column is the transparency); ‘Color’,[0.0 0.0 1.0 0.3], but when I build a colormap with four columns and try to use that instead of using the MarkerFaceAlpha option, the colormap command rejects it.
I have googled this and searched Matlab Answers, but nothing useful was found.
Any suggestions would be gratefully received. Thank you.
Gordon Cooper Hello,
I’m using bubblechart to display my data as shown below;
bubblechart(x2xz,z2xz,ones(size(x2xz)),n2xz,’MarkerFaceAlpha’,0.1,’MarkerEdgeAlpha’,0.2);
-this works. However it would be better if I could make MarkerFaceAlpha a variable, so that it changes based on the value of n2xz (which currently controls the colour of the bubbles). Unfortunately MarkerFaceAlpha has to be a scalar, not a vector, with bubblechart.
The plot command accepts colours in this format (where the fourth column is the transparency); ‘Color’,[0.0 0.0 1.0 0.3], but when I build a colormap with four columns and try to use that instead of using the MarkerFaceAlpha option, the colormap command rejects it.
I have googled this and searched Matlab Answers, but nothing useful was found.
Any suggestions would be gratefully received. Thank you.
Gordon Cooper bubblechart, transparency MATLAB Answers — New Questions
Ziegler Nichols PID Method
Hi,
I have a problem ,this is my G(s)=59000/(s^2+59000)
I want to apply the tangent method of Ziegler-Nichols, but my step is a sinusoid undumped. How I can approximate my G(s) to apply this method? Thanks very much.Hi,
I have a problem ,this is my G(s)=59000/(s^2+59000)
I want to apply the tangent method of Ziegler-Nichols, but my step is a sinusoid undumped. How I can approximate my G(s) to apply this method? Thanks very much. Hi,
I have a problem ,this is my G(s)=59000/(s^2+59000)
I want to apply the tangent method of Ziegler-Nichols, but my step is a sinusoid undumped. How I can approximate my G(s) to apply this method? Thanks very much. pid, ziegler nichlos MATLAB Answers — New Questions
My DDPG agent model is generating same output from every simulation.
I trained a rlDDPGagent(a biped walking robot) and simulated, but it always generates a same walking from every simulation.
However, I need a different gaits to acquire several sensor data. The code below is the training and agent option code. I used the msra-walking-robot-master code from matlab github.
% Create DDPG agent and training options for walking robot example
%
% Copyright 2019 The MathWorks, Inc.
%% DDPG Agent Options
agentOptions = rlDDPGAgentOptions;
agentOptions.SampleTime = Ts;
agentOptions.DiscountFactor = 0.99;
agentOptions.MiniBatchSize = 128;
agentOptions.ExperienceBufferLength = 1e6;
agentOptions.TargetSmoothFactor = 1e-3;
agentOptions.NoiseOptions.MeanAttractionConstant = 5;
agentOptions.NoiseOptions.Variance = 0.4;
agentOptions.NoiseOptions.VarianceDecayRate = 1e-5;
%% Training Options
trainingOptions = rlTrainingOptions;
trainingOptions.MaxEpisodes = 5000;
trainingOptions.MaxStepsPerEpisode = Tf/Ts;
trainingOptions.ScoreAveragingWindowLength = 100;
trainingOptions.StopTrainingCriteria = ‘AverageReward’;
trainingOptions.StopTrainingValue = 110;
trainingOptions.SaveAgentCriteria = ‘EpisodeReward’;
trainingOptions.SaveAgentValue = 150;
trainingOptions.Plots = ‘training-progress’;
trainingOptions.Verbose = true;
if useParallel
trainingOptions.Parallelization = ‘async’;
trainingOptions.ParallelizationOptions.StepsUntilDataIsSent = 32;
end
The code below is training code:
% Walking Robot — DDPG Agent Training Script (2D)
% Copyright 2019 The MathWorks, Inc.
warning off parallel:gpu:device:DeviceLibsNeedsRecompiling %don’t show the warning
%% SET UP ENVIRONMENT
% Speedup options
useFastRestart = true;
useGPU = false;
useParallel = true;
% Create the observation info
numObs = 31;
observationInfo = rlNumericSpec([numObs 1]);
observationInfo.Name = ‘observations’;
% create the action info
numAct = 6;
actionInfo = rlNumericSpec([numAct 1],’LowerLimit’,-1,’UpperLimit’, 1);
actionInfo.Name = ‘foot_torque’;
% Environment
mdl = ‘walkingRobotRL2D’;
load_system(mdl);
blk = [mdl,’/RL Agent’];
env = rlSimulinkEnv(mdl,blk,observationInfo,actionInfo);
env.ResetFcn = @(in)walkerResetFcn(in,upper_leg_length/100,lower_leg_length/100,h/100,’2D’);
if ~useFastRestart
env.UseFastRestart = ‘off’;
end
%% CREATE NEURAL NETWORKS
createDDPGNetworks;
%% CREATE AND TRAIN AGENT
createDDPGOptions;
agent = rlDDPGAgent(actor,critic,agentOptions);
trainingResults = train(agent,env,trainingOptions)
%% SAVE AGENT
reset(agent); % Clears the experience buffer
curDir = pwd;
saveDir = ‘savedAgents’;
cd(saveDir)
save([‘trainedAgent_2D_’ datestr(now,’mm_DD_YYYY_HHMM’)],’agent’,’trainingResults’,’trainingOptions.MaxEpisodes’);
cd(curDir)
The code below is the simulation code:
% Simulates the walking robot model
%% Setup
clc; close all;
robotParametersRL
% Create the observation info
numObs = 31;
observationInfo = rlNumericSpec([numObs 1]);
observationInfo.Name = ‘observations’;
% create the action info
numAct = 6;
actionInfo = rlNumericSpec([numAct 1],’LowerLimit’,-1,’UpperLimit’, 1);
actionInfo.Name = ‘foot_torque’;
% Environment
mdl = ‘walkingRobotRL2D’;
load_system(mdl);
blk = [mdl,’/RL Agent’];
env = rlSimulinkEnv(mdl,blk,observationInfo,actionInfo);
load trainedAgent_2D_04_25_2024_1541_5000 %load agent
%action = getAction(agent);
simOpts = rlSimulationOptions;
simOpts.MaxSteps = 1000;
simOpts.NumSimulations = 3;
%plot(env);
reset(env);
experience = sim(env,agent,simOpts);
The result of the code always show the same gait. Is there any method to get different output from every simulation?
Thank you so much!I trained a rlDDPGagent(a biped walking robot) and simulated, but it always generates a same walking from every simulation.
However, I need a different gaits to acquire several sensor data. The code below is the training and agent option code. I used the msra-walking-robot-master code from matlab github.
% Create DDPG agent and training options for walking robot example
%
% Copyright 2019 The MathWorks, Inc.
%% DDPG Agent Options
agentOptions = rlDDPGAgentOptions;
agentOptions.SampleTime = Ts;
agentOptions.DiscountFactor = 0.99;
agentOptions.MiniBatchSize = 128;
agentOptions.ExperienceBufferLength = 1e6;
agentOptions.TargetSmoothFactor = 1e-3;
agentOptions.NoiseOptions.MeanAttractionConstant = 5;
agentOptions.NoiseOptions.Variance = 0.4;
agentOptions.NoiseOptions.VarianceDecayRate = 1e-5;
%% Training Options
trainingOptions = rlTrainingOptions;
trainingOptions.MaxEpisodes = 5000;
trainingOptions.MaxStepsPerEpisode = Tf/Ts;
trainingOptions.ScoreAveragingWindowLength = 100;
trainingOptions.StopTrainingCriteria = ‘AverageReward’;
trainingOptions.StopTrainingValue = 110;
trainingOptions.SaveAgentCriteria = ‘EpisodeReward’;
trainingOptions.SaveAgentValue = 150;
trainingOptions.Plots = ‘training-progress’;
trainingOptions.Verbose = true;
if useParallel
trainingOptions.Parallelization = ‘async’;
trainingOptions.ParallelizationOptions.StepsUntilDataIsSent = 32;
end
The code below is training code:
% Walking Robot — DDPG Agent Training Script (2D)
% Copyright 2019 The MathWorks, Inc.
warning off parallel:gpu:device:DeviceLibsNeedsRecompiling %don’t show the warning
%% SET UP ENVIRONMENT
% Speedup options
useFastRestart = true;
useGPU = false;
useParallel = true;
% Create the observation info
numObs = 31;
observationInfo = rlNumericSpec([numObs 1]);
observationInfo.Name = ‘observations’;
% create the action info
numAct = 6;
actionInfo = rlNumericSpec([numAct 1],’LowerLimit’,-1,’UpperLimit’, 1);
actionInfo.Name = ‘foot_torque’;
% Environment
mdl = ‘walkingRobotRL2D’;
load_system(mdl);
blk = [mdl,’/RL Agent’];
env = rlSimulinkEnv(mdl,blk,observationInfo,actionInfo);
env.ResetFcn = @(in)walkerResetFcn(in,upper_leg_length/100,lower_leg_length/100,h/100,’2D’);
if ~useFastRestart
env.UseFastRestart = ‘off’;
end
%% CREATE NEURAL NETWORKS
createDDPGNetworks;
%% CREATE AND TRAIN AGENT
createDDPGOptions;
agent = rlDDPGAgent(actor,critic,agentOptions);
trainingResults = train(agent,env,trainingOptions)
%% SAVE AGENT
reset(agent); % Clears the experience buffer
curDir = pwd;
saveDir = ‘savedAgents’;
cd(saveDir)
save([‘trainedAgent_2D_’ datestr(now,’mm_DD_YYYY_HHMM’)],’agent’,’trainingResults’,’trainingOptions.MaxEpisodes’);
cd(curDir)
The code below is the simulation code:
% Simulates the walking robot model
%% Setup
clc; close all;
robotParametersRL
% Create the observation info
numObs = 31;
observationInfo = rlNumericSpec([numObs 1]);
observationInfo.Name = ‘observations’;
% create the action info
numAct = 6;
actionInfo = rlNumericSpec([numAct 1],’LowerLimit’,-1,’UpperLimit’, 1);
actionInfo.Name = ‘foot_torque’;
% Environment
mdl = ‘walkingRobotRL2D’;
load_system(mdl);
blk = [mdl,’/RL Agent’];
env = rlSimulinkEnv(mdl,blk,observationInfo,actionInfo);
load trainedAgent_2D_04_25_2024_1541_5000 %load agent
%action = getAction(agent);
simOpts = rlSimulationOptions;
simOpts.MaxSteps = 1000;
simOpts.NumSimulations = 3;
%plot(env);
reset(env);
experience = sim(env,agent,simOpts);
The result of the code always show the same gait. Is there any method to get different output from every simulation?
Thank you so much! I trained a rlDDPGagent(a biped walking robot) and simulated, but it always generates a same walking from every simulation.
However, I need a different gaits to acquire several sensor data. The code below is the training and agent option code. I used the msra-walking-robot-master code from matlab github.
% Create DDPG agent and training options for walking robot example
%
% Copyright 2019 The MathWorks, Inc.
%% DDPG Agent Options
agentOptions = rlDDPGAgentOptions;
agentOptions.SampleTime = Ts;
agentOptions.DiscountFactor = 0.99;
agentOptions.MiniBatchSize = 128;
agentOptions.ExperienceBufferLength = 1e6;
agentOptions.TargetSmoothFactor = 1e-3;
agentOptions.NoiseOptions.MeanAttractionConstant = 5;
agentOptions.NoiseOptions.Variance = 0.4;
agentOptions.NoiseOptions.VarianceDecayRate = 1e-5;
%% Training Options
trainingOptions = rlTrainingOptions;
trainingOptions.MaxEpisodes = 5000;
trainingOptions.MaxStepsPerEpisode = Tf/Ts;
trainingOptions.ScoreAveragingWindowLength = 100;
trainingOptions.StopTrainingCriteria = ‘AverageReward’;
trainingOptions.StopTrainingValue = 110;
trainingOptions.SaveAgentCriteria = ‘EpisodeReward’;
trainingOptions.SaveAgentValue = 150;
trainingOptions.Plots = ‘training-progress’;
trainingOptions.Verbose = true;
if useParallel
trainingOptions.Parallelization = ‘async’;
trainingOptions.ParallelizationOptions.StepsUntilDataIsSent = 32;
end
The code below is training code:
% Walking Robot — DDPG Agent Training Script (2D)
% Copyright 2019 The MathWorks, Inc.
warning off parallel:gpu:device:DeviceLibsNeedsRecompiling %don’t show the warning
%% SET UP ENVIRONMENT
% Speedup options
useFastRestart = true;
useGPU = false;
useParallel = true;
% Create the observation info
numObs = 31;
observationInfo = rlNumericSpec([numObs 1]);
observationInfo.Name = ‘observations’;
% create the action info
numAct = 6;
actionInfo = rlNumericSpec([numAct 1],’LowerLimit’,-1,’UpperLimit’, 1);
actionInfo.Name = ‘foot_torque’;
% Environment
mdl = ‘walkingRobotRL2D’;
load_system(mdl);
blk = [mdl,’/RL Agent’];
env = rlSimulinkEnv(mdl,blk,observationInfo,actionInfo);
env.ResetFcn = @(in)walkerResetFcn(in,upper_leg_length/100,lower_leg_length/100,h/100,’2D’);
if ~useFastRestart
env.UseFastRestart = ‘off’;
end
%% CREATE NEURAL NETWORKS
createDDPGNetworks;
%% CREATE AND TRAIN AGENT
createDDPGOptions;
agent = rlDDPGAgent(actor,critic,agentOptions);
trainingResults = train(agent,env,trainingOptions)
%% SAVE AGENT
reset(agent); % Clears the experience buffer
curDir = pwd;
saveDir = ‘savedAgents’;
cd(saveDir)
save([‘trainedAgent_2D_’ datestr(now,’mm_DD_YYYY_HHMM’)],’agent’,’trainingResults’,’trainingOptions.MaxEpisodes’);
cd(curDir)
The code below is the simulation code:
% Simulates the walking robot model
%% Setup
clc; close all;
robotParametersRL
% Create the observation info
numObs = 31;
observationInfo = rlNumericSpec([numObs 1]);
observationInfo.Name = ‘observations’;
% create the action info
numAct = 6;
actionInfo = rlNumericSpec([numAct 1],’LowerLimit’,-1,’UpperLimit’, 1);
actionInfo.Name = ‘foot_torque’;
% Environment
mdl = ‘walkingRobotRL2D’;
load_system(mdl);
blk = [mdl,’/RL Agent’];
env = rlSimulinkEnv(mdl,blk,observationInfo,actionInfo);
load trainedAgent_2D_04_25_2024_1541_5000 %load agent
%action = getAction(agent);
simOpts = rlSimulationOptions;
simOpts.MaxSteps = 1000;
simOpts.NumSimulations = 3;
%plot(env);
reset(env);
experience = sim(env,agent,simOpts);
The result of the code always show the same gait. Is there any method to get different output from every simulation?
Thank you so much! simulink, ddpg, rl, reinforcement learning, biped robot, simulation MATLAB Answers — New Questions
How to use PMSM from SimPowerSystems block with Simscape Model
Hello together,
I’m trying modelling of actuator which is powered by PMSM from SimPowerSystems block. I have connected the motor ‘S’ port with other mechanical input such as gear and spring and ideal torque source but when I vary papameters of spring there is no change in output position or speed. Attached the similar work insted of stepper i wanted to use PMSM block with ‘S’ port.
How can I connect the PSMS with the mechanical model, so that the robot is I can get accurate readings?
Thank you for your help.
Kind regards,
DhananjayHello together,
I’m trying modelling of actuator which is powered by PMSM from SimPowerSystems block. I have connected the motor ‘S’ port with other mechanical input such as gear and spring and ideal torque source but when I vary papameters of spring there is no change in output position or speed. Attached the similar work insted of stepper i wanted to use PMSM block with ‘S’ port.
How can I connect the PSMS with the mechanical model, so that the robot is I can get accurate readings?
Thank you for your help.
Kind regards,
Dhananjay Hello together,
I’m trying modelling of actuator which is powered by PMSM from SimPowerSystems block. I have connected the motor ‘S’ port with other mechanical input such as gear and spring and ideal torque source but when I vary papameters of spring there is no change in output position or speed. Attached the similar work insted of stepper i wanted to use PMSM block with ‘S’ port.
How can I connect the PSMS with the mechanical model, so that the robot is I can get accurate readings?
Thank you for your help.
Kind regards,
Dhananjay pmsm, simscape, simpowersystems, bldc MATLAB Answers — New Questions
[Simscape] Having two thermal liquid loops with different thermal liquid settings?
I’m modeling a two-loop system on both sides of a heat exchanger and clearly each loop uses different heat transfer fluid.
So I though I should be able to connect two different thermal liquid setting blocks on each side of the heat exchanger, but I’m getting the following error.
"Failed to propagate domain parameters. Domain parameters are propagated to the same set of nodes from sources: ‘Thermal_Liquid_Settings_TL.A’ and ‘SecondaryLoop.Thermal_Liquid_Settings_TL2.A’. Each node may only have at most one source of propagation."
Doesn’t this feel like a bug in the current heat exchanger model? Surely the properties could be different. The version I’m on is 2021b. I’ll try to look for ways to bypass it (maybe first go to a newer version), but if anyone happens to know about this issue, please share your ideas.I’m modeling a two-loop system on both sides of a heat exchanger and clearly each loop uses different heat transfer fluid.
So I though I should be able to connect two different thermal liquid setting blocks on each side of the heat exchanger, but I’m getting the following error.
"Failed to propagate domain parameters. Domain parameters are propagated to the same set of nodes from sources: ‘Thermal_Liquid_Settings_TL.A’ and ‘SecondaryLoop.Thermal_Liquid_Settings_TL2.A’. Each node may only have at most one source of propagation."
Doesn’t this feel like a bug in the current heat exchanger model? Surely the properties could be different. The version I’m on is 2021b. I’ll try to look for ways to bypass it (maybe first go to a newer version), but if anyone happens to know about this issue, please share your ideas. I’m modeling a two-loop system on both sides of a heat exchanger and clearly each loop uses different heat transfer fluid.
So I though I should be able to connect two different thermal liquid setting blocks on each side of the heat exchanger, but I’m getting the following error.
"Failed to propagate domain parameters. Domain parameters are propagated to the same set of nodes from sources: ‘Thermal_Liquid_Settings_TL.A’ and ‘SecondaryLoop.Thermal_Liquid_Settings_TL2.A’. Each node may only have at most one source of propagation."
Doesn’t this feel like a bug in the current heat exchanger model? Surely the properties could be different. The version I’m on is 2021b. I’ll try to look for ways to bypass it (maybe first go to a newer version), but if anyone happens to know about this issue, please share your ideas. simscape MATLAB Answers — New Questions
How do I call a function from the command window
myEquation(2)
function myEquation (x)
a = 0.4361836;
b = 0.1201676;
c = 0.937298;
r = exp(-0.5*(x^2))/(2*pi) ;
t = 1/(1+(0.3326*x)) ;
phi = 0.5 – r*((a*t)-(b*(t^2))+(c*(t^3))) ;
fprintf(‘The value of Φ(x) is: %i’, phi)
fprintf(‘n’)
end
I have this code, and it works properly, however, I need a way to be able to call it from the command window. The line myEquation(2) auto inputs the value as 2, but I need to be able to enter other values without editing the code. Should I use an input prompt to prompt the user for a value of x to run my equation on?myEquation(2)
function myEquation (x)
a = 0.4361836;
b = 0.1201676;
c = 0.937298;
r = exp(-0.5*(x^2))/(2*pi) ;
t = 1/(1+(0.3326*x)) ;
phi = 0.5 – r*((a*t)-(b*(t^2))+(c*(t^3))) ;
fprintf(‘The value of Φ(x) is: %i’, phi)
fprintf(‘n’)
end
I have this code, and it works properly, however, I need a way to be able to call it from the command window. The line myEquation(2) auto inputs the value as 2, but I need to be able to enter other values without editing the code. Should I use an input prompt to prompt the user for a value of x to run my equation on? myEquation(2)
function myEquation (x)
a = 0.4361836;
b = 0.1201676;
c = 0.937298;
r = exp(-0.5*(x^2))/(2*pi) ;
t = 1/(1+(0.3326*x)) ;
phi = 0.5 – r*((a*t)-(b*(t^2))+(c*(t^3))) ;
fprintf(‘The value of Φ(x) is: %i’, phi)
fprintf(‘n’)
end
I have this code, and it works properly, however, I need a way to be able to call it from the command window. The line myEquation(2) auto inputs the value as 2, but I need to be able to enter other values without editing the code. Should I use an input prompt to prompt the user for a value of x to run my equation on? function, duplicate post MATLAB Answers — New Questions
how to aviod the two loops
I have a code:
x=linspace(-10,10,10001);
y=linspace(-5,5,20001);
A=[];
for j=1:length(x)
for k=1:length(y)
A=[A;x(j),y(k)];
end
end
The computation is very slow due to the two loops, so How can I aviod the two loops in this code?
Thanks very much!I have a code:
x=linspace(-10,10,10001);
y=linspace(-5,5,20001);
A=[];
for j=1:length(x)
for k=1:length(y)
A=[A;x(j),y(k)];
end
end
The computation is very slow due to the two loops, so How can I aviod the two loops in this code?
Thanks very much! I have a code:
x=linspace(-10,10,10001);
y=linspace(-5,5,20001);
A=[];
for j=1:length(x)
for k=1:length(y)
A=[A;x(j),y(k)];
end
end
The computation is very slow due to the two loops, so How can I aviod the two loops in this code?
Thanks very much! loops MATLAB Answers — New Questions
What is the correct use of the “RGB2Lab” function in this situation?
Hi, what I am looking to do is an analysis on the color change of a sample over time.
What I thought of doing is the following:
1- A mask of the first photo that will be used in all the following ones. In this way observe only the sample.
2- Using the mask to obtain the average value of the RGB channels of the sample in each of the photos.
3- Use the "RGB2Lab" function to obtain the values in Lab mode for each photo.
4-From these last values calculate the color difference "Delta E" for each of the photos with respect to the first one.
My doubts are then the following (if you have any recommendation for any of the above steps I will also be grateful, I am new to image analysis and I learned about Lab mode last week):
Does it make sense to occupy Lab mode as I am doing?
From what I understand the "RGB2Lab" function has other inputs that are related to the light used. If I used a white fluorescent light I should use the light standard "F" or am I wrong?
However this standard is not available for the function, any advice?
This is the sample:
EDIT: I was quick to ask the question myself. But I found some links to other answered questions that, I think, encapsulate everything I asked.
https://la.mathworks.com/matlabcentral/answers/23013-makecform-srgb2lab?#comment_443644
https://la.mathworks.com/matlabcentral/answers/797742-how-to-separate-the-rgb-channels-from-an-image-and-get-the-average-of-each-rgb-channel-separetly?s_tid=sug_suHi, what I am looking to do is an analysis on the color change of a sample over time.
What I thought of doing is the following:
1- A mask of the first photo that will be used in all the following ones. In this way observe only the sample.
2- Using the mask to obtain the average value of the RGB channels of the sample in each of the photos.
3- Use the "RGB2Lab" function to obtain the values in Lab mode for each photo.
4-From these last values calculate the color difference "Delta E" for each of the photos with respect to the first one.
My doubts are then the following (if you have any recommendation for any of the above steps I will also be grateful, I am new to image analysis and I learned about Lab mode last week):
Does it make sense to occupy Lab mode as I am doing?
From what I understand the "RGB2Lab" function has other inputs that are related to the light used. If I used a white fluorescent light I should use the light standard "F" or am I wrong?
However this standard is not available for the function, any advice?
This is the sample:
EDIT: I was quick to ask the question myself. But I found some links to other answered questions that, I think, encapsulate everything I asked.
https://la.mathworks.com/matlabcentral/answers/23013-makecform-srgb2lab?#comment_443644
https://la.mathworks.com/matlabcentral/answers/797742-how-to-separate-the-rgb-channels-from-an-image-and-get-the-average-of-each-rgb-channel-separetly?s_tid=sug_su Hi, what I am looking to do is an analysis on the color change of a sample over time.
What I thought of doing is the following:
1- A mask of the first photo that will be used in all the following ones. In this way observe only the sample.
2- Using the mask to obtain the average value of the RGB channels of the sample in each of the photos.
3- Use the "RGB2Lab" function to obtain the values in Lab mode for each photo.
4-From these last values calculate the color difference "Delta E" for each of the photos with respect to the first one.
My doubts are then the following (if you have any recommendation for any of the above steps I will also be grateful, I am new to image analysis and I learned about Lab mode last week):
Does it make sense to occupy Lab mode as I am doing?
From what I understand the "RGB2Lab" function has other inputs that are related to the light used. If I used a white fluorescent light I should use the light standard "F" or am I wrong?
However this standard is not available for the function, any advice?
This is the sample:
EDIT: I was quick to ask the question myself. But I found some links to other answered questions that, I think, encapsulate everything I asked.
https://la.mathworks.com/matlabcentral/answers/23013-makecform-srgb2lab?#comment_443644
https://la.mathworks.com/matlabcentral/answers/797742-how-to-separate-the-rgb-channels-from-an-image-and-get-the-average-of-each-rgb-channel-separetly?s_tid=sug_su image analysis, rgb MATLAB Answers — New Questions
Webcam cannot be initialized properly. Please check if the device USB Camera: USB Camera (usb-0000:01:00.0-1.3) is available and free to use.
matlab–
1.r=raspi;–Successfully established connection
Raspberry Pi–
2. lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 0bda:3035 Realtek Semiconductor Corp.
Bus 001 Device 005: ID 25a7:fa67
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
3. fswebcam -r 640*480 a.png
— Opening /dev/video0…
Trying source module v4l2…
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 640x-1 to 640×480.
— Capturing frame…
Captured frame in 0.00 seconds.
— Processing captured image…Writing JPEG image to ‘a.png’matlab–
1.r=raspi;–Successfully established connection
Raspberry Pi–
2. lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 0bda:3035 Realtek Semiconductor Corp.
Bus 001 Device 005: ID 25a7:fa67
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
3. fswebcam -r 640*480 a.png
— Opening /dev/video0…
Trying source module v4l2…
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 640x-1 to 640×480.
— Capturing frame…
Captured frame in 0.00 seconds.
— Processing captured image…Writing JPEG image to ‘a.png’ matlab–
1.r=raspi;–Successfully established connection
Raspberry Pi–
2. lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 0bda:3035 Realtek Semiconductor Corp.
Bus 001 Device 005: ID 25a7:fa67
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
3. fswebcam -r 640*480 a.png
— Opening /dev/video0…
Trying source module v4l2…
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 640x-1 to 640×480.
— Capturing frame…
Captured frame in 0.00 seconds.
— Processing captured image…Writing JPEG image to ‘a.png’ matlab,raspberry pi MATLAB Answers — New Questions
How to extract a slider value?
%Slider
fig = uifigure(‘Position’,[100 100 350 275]);
pnl1 = uipanel(fig);
sld1 = uislider(pnl1,’Position’,[100 40 120 3],… ‘ValueChangingFcn’,@(sld,event1) slider1(event1));
sld1.Limits = [-100 100];
sld2 = uislider(pnl1,’Position’,[100 100 120 3],… ‘ValueChangingFcn’,@(sld,event2) slider2(event2));
sld2.Limits = [-100 100];
sld3 = uislider(pnl1,’Position’,[100 180 120 3],… ‘ValueChangingFcn’,@(sld,event3) slider3(event3));
sld3.Limits = [-100 100];
I’m trying to make a program to extract the power of my engine from the sliders I declared(each one corresponds to one engine). So I need to extract the value of each slider when i dragg it as an integer variable, if anyone can help it will be great.
Thanks!%Slider
fig = uifigure(‘Position’,[100 100 350 275]);
pnl1 = uipanel(fig);
sld1 = uislider(pnl1,’Position’,[100 40 120 3],… ‘ValueChangingFcn’,@(sld,event1) slider1(event1));
sld1.Limits = [-100 100];
sld2 = uislider(pnl1,’Position’,[100 100 120 3],… ‘ValueChangingFcn’,@(sld,event2) slider2(event2));
sld2.Limits = [-100 100];
sld3 = uislider(pnl1,’Position’,[100 180 120 3],… ‘ValueChangingFcn’,@(sld,event3) slider3(event3));
sld3.Limits = [-100 100];
I’m trying to make a program to extract the power of my engine from the sliders I declared(each one corresponds to one engine). So I need to extract the value of each slider when i dragg it as an integer variable, if anyone can help it will be great.
Thanks! %Slider
fig = uifigure(‘Position’,[100 100 350 275]);
pnl1 = uipanel(fig);
sld1 = uislider(pnl1,’Position’,[100 40 120 3],… ‘ValueChangingFcn’,@(sld,event1) slider1(event1));
sld1.Limits = [-100 100];
sld2 = uislider(pnl1,’Position’,[100 100 120 3],… ‘ValueChangingFcn’,@(sld,event2) slider2(event2));
sld2.Limits = [-100 100];
sld3 = uislider(pnl1,’Position’,[100 180 120 3],… ‘ValueChangingFcn’,@(sld,event3) slider3(event3));
sld3.Limits = [-100 100];
I’m trying to make a program to extract the power of my engine from the sliders I declared(each one corresponds to one engine). So I need to extract the value of each slider when i dragg it as an integer variable, if anyone can help it will be great.
Thanks! sliders MATLAB Answers — New Questions
FWT_PO Formula
Hello,
I need the mathematical formula of FWT_PO (forward wavelet transform periodized orthogonal).
ThanksHello,
I need the mathematical formula of FWT_PO (forward wavelet transform periodized orthogonal).
Thanks Hello,
I need the mathematical formula of FWT_PO (forward wavelet transform periodized orthogonal).
Thanks wavelet, mathematics MATLAB Answers — New Questions
creating a function for linear interpolation based on two changing states
So I’m trying to add in linear interpolation into a fitness equation that has two information states. I was talking about it with my professor and he said I could make a function that combines the probability of the information states being between two integers multiplied by the fitness of being at those information states. So looking something like this:
j=2.3
k=4.5
%the function would be combining all possible combinations
%((there is also a physical state (x) and a time state for the fitness function))
p(j=2,k=4)*Ft(x,2,4,t)+
p(j=3,k=4)*Ft(x,3,4,t)+
p(j=2,k=5)*Ft(x,2,5,t)+
p(j=3,k=5)*Ft(x,3,5,t)
How would I create a function that would do this, but for any combination of numbers?So I’m trying to add in linear interpolation into a fitness equation that has two information states. I was talking about it with my professor and he said I could make a function that combines the probability of the information states being between two integers multiplied by the fitness of being at those information states. So looking something like this:
j=2.3
k=4.5
%the function would be combining all possible combinations
%((there is also a physical state (x) and a time state for the fitness function))
p(j=2,k=4)*Ft(x,2,4,t)+
p(j=3,k=4)*Ft(x,3,4,t)+
p(j=2,k=5)*Ft(x,2,5,t)+
p(j=3,k=5)*Ft(x,3,5,t)
How would I create a function that would do this, but for any combination of numbers? So I’m trying to add in linear interpolation into a fitness equation that has two information states. I was talking about it with my professor and he said I could make a function that combines the probability of the information states being between two integers multiplied by the fitness of being at those information states. So looking something like this:
j=2.3
k=4.5
%the function would be combining all possible combinations
%((there is also a physical state (x) and a time state for the fitness function))
p(j=2,k=4)*Ft(x,2,4,t)+
p(j=3,k=4)*Ft(x,3,4,t)+
p(j=2,k=5)*Ft(x,2,5,t)+
p(j=3,k=5)*Ft(x,3,5,t)
How would I create a function that would do this, but for any combination of numbers? linear, interpolation MATLAB Answers — New Questions
How do I install Matlab trial on ubuntu remote ubuntu machine through a command line?
I have looked at this https://www.mathworks.com/help/install/ug/install-noninteractively-silent-installation.html
However , I’m not sure that the contents of the file should be. Can someone please share a template to get a trail version installed?I have looked at this https://www.mathworks.com/help/install/ug/install-noninteractively-silent-installation.html
However , I’m not sure that the contents of the file should be. Can someone please share a template to get a trail version installed? I have looked at this https://www.mathworks.com/help/install/ug/install-noninteractively-silent-installation.html
However , I’m not sure that the contents of the file should be. Can someone please share a template to get a trail version installed? installation MATLAB Answers — New Questions