Category: Matlab
Category Archives: Matlab
matlab reinforcement learning module RL Agent
I would like to ask how to use the agent module in simulink for the matlab version before 2020, because the version before 2020 does not have RL agent encapsulationI would like to ask how to use the agent module in simulink for the matlab version before 2020, because the version before 2020 does not have RL agent encapsulation I would like to ask how to use the agent module in simulink for the matlab version before 2020, because the version before 2020 does not have RL agent encapsulation reinforcement learning MATLAB Answers — New Questions
Need the graph for F,G,theta
conedisk2()
function conedisk2
% Parameter values
A1 = 1.10629;
A2 = 1.15;
A3 = 1.15;
A4 = 1.15;
A5 = 1.15;
A6 = 1.15;
M = 0.2;
Grt = 5;
Pr = 0.71;
R = 0.2;
Ec = 0.1;
Q = 0.1;
Rew = 12;
Red = 12;
n = -1;
g1 = 0;
g2 = 0;
g3 = 0;
g4 = 0;
inf = 0.06992681;
% Set solver options to increase the maximum number of mesh points
options = bvpset(‘RelTol’, 1e-5, ‘AbsTol’, 1e-7, ‘NMax’, 5000);
% Defining parameters
solinit = bvpinit(linspace(0, 1, 200), [0 g1 g2 Rew g3 0 1 g4]);
sol = bvp4c(@bvp2D, @bc2D, solinit);
x = sol.x;
y = sol.y;
% Plotting of the velocity
figure(1)
plot(x, y(1,:), ‘linewidth’, 1)
hold on
xlabel(‘eta’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘F(eta)’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
hold off
% Plotting of G
figure(2)
plot(x, y(5,:), ‘linewidth’, 1)
hold on
xlabel(‘eta ‘, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘G(eta) ‘, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
hold off
% Plotting of theta
figure(3)
plot(x, y(7,:), ‘linewidth’, 1)
hold on
xlabel(‘eta’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘theta(eta)’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
hold off
% Residual of the boundary conditions
function res = bc2D(y0, yinf)
res = [y0(1);yinf(1); y0(4); yinf(4);y0(5)-Rew; yinf(5)-Red;y0(7)-1; yinf(7)];
end
% System of First Order ODEs
function dydx = bvp2D(eta, y)
yy1 = (-(1+eta^2)*((10*A1*eta+A2*eta*y(1)-A2*y(4))*y(3))-3*(2*A1+7*A1*(eta^2)+A2*(2*eta^2+1)*y(1)-A2*eta*y(4))*y(2)-2*A2*y(5)*y(6)-3*(A1+A2*y(1))*y(4)+A3*M*y(2)-A4*Grt*y(8))/(A1*(1+eta^2)^2);
yy2 = eta*y(2);
yy3 = (-3*A1*eta*y(6)-A2*(eta*y(1)-y(4))*y(6)+A3*M*y(5))/(A1*(eta^2+1));
yy4 = ((A5+4/3*R)*((eta*((2*n)-1))*y(8)+n^2*y(7))-A3*Pr*M*Ec*(y(1)^2+y(5)^2)-Pr*Q*y(7)+A6*Pr*(y(4)*y(8)+n*y(1)*y(7)-eta*y(1)*y(8)))/(A5+4/3*R)*(1+eta^2);
dydx = [y(2); y(3); yy1; yy2; y(6); yy3; y(8); yy4];
end
end
The code is running but I am unable to get the graph what i have attached for radial velocity and azimuthal velocityconedisk2()
function conedisk2
% Parameter values
A1 = 1.10629;
A2 = 1.15;
A3 = 1.15;
A4 = 1.15;
A5 = 1.15;
A6 = 1.15;
M = 0.2;
Grt = 5;
Pr = 0.71;
R = 0.2;
Ec = 0.1;
Q = 0.1;
Rew = 12;
Red = 12;
n = -1;
g1 = 0;
g2 = 0;
g3 = 0;
g4 = 0;
inf = 0.06992681;
% Set solver options to increase the maximum number of mesh points
options = bvpset(‘RelTol’, 1e-5, ‘AbsTol’, 1e-7, ‘NMax’, 5000);
% Defining parameters
solinit = bvpinit(linspace(0, 1, 200), [0 g1 g2 Rew g3 0 1 g4]);
sol = bvp4c(@bvp2D, @bc2D, solinit);
x = sol.x;
y = sol.y;
% Plotting of the velocity
figure(1)
plot(x, y(1,:), ‘linewidth’, 1)
hold on
xlabel(‘eta’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘F(eta)’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
hold off
% Plotting of G
figure(2)
plot(x, y(5,:), ‘linewidth’, 1)
hold on
xlabel(‘eta ‘, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘G(eta) ‘, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
hold off
% Plotting of theta
figure(3)
plot(x, y(7,:), ‘linewidth’, 1)
hold on
xlabel(‘eta’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘theta(eta)’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
hold off
% Residual of the boundary conditions
function res = bc2D(y0, yinf)
res = [y0(1);yinf(1); y0(4); yinf(4);y0(5)-Rew; yinf(5)-Red;y0(7)-1; yinf(7)];
end
% System of First Order ODEs
function dydx = bvp2D(eta, y)
yy1 = (-(1+eta^2)*((10*A1*eta+A2*eta*y(1)-A2*y(4))*y(3))-3*(2*A1+7*A1*(eta^2)+A2*(2*eta^2+1)*y(1)-A2*eta*y(4))*y(2)-2*A2*y(5)*y(6)-3*(A1+A2*y(1))*y(4)+A3*M*y(2)-A4*Grt*y(8))/(A1*(1+eta^2)^2);
yy2 = eta*y(2);
yy3 = (-3*A1*eta*y(6)-A2*(eta*y(1)-y(4))*y(6)+A3*M*y(5))/(A1*(eta^2+1));
yy4 = ((A5+4/3*R)*((eta*((2*n)-1))*y(8)+n^2*y(7))-A3*Pr*M*Ec*(y(1)^2+y(5)^2)-Pr*Q*y(7)+A6*Pr*(y(4)*y(8)+n*y(1)*y(7)-eta*y(1)*y(8)))/(A5+4/3*R)*(1+eta^2);
dydx = [y(2); y(3); yy1; yy2; y(6); yy3; y(8); yy4];
end
end
The code is running but I am unable to get the graph what i have attached for radial velocity and azimuthal velocity conedisk2()
function conedisk2
% Parameter values
A1 = 1.10629;
A2 = 1.15;
A3 = 1.15;
A4 = 1.15;
A5 = 1.15;
A6 = 1.15;
M = 0.2;
Grt = 5;
Pr = 0.71;
R = 0.2;
Ec = 0.1;
Q = 0.1;
Rew = 12;
Red = 12;
n = -1;
g1 = 0;
g2 = 0;
g3 = 0;
g4 = 0;
inf = 0.06992681;
% Set solver options to increase the maximum number of mesh points
options = bvpset(‘RelTol’, 1e-5, ‘AbsTol’, 1e-7, ‘NMax’, 5000);
% Defining parameters
solinit = bvpinit(linspace(0, 1, 200), [0 g1 g2 Rew g3 0 1 g4]);
sol = bvp4c(@bvp2D, @bc2D, solinit);
x = sol.x;
y = sol.y;
% Plotting of the velocity
figure(1)
plot(x, y(1,:), ‘linewidth’, 1)
hold on
xlabel(‘eta’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘F(eta)’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
hold off
% Plotting of G
figure(2)
plot(x, y(5,:), ‘linewidth’, 1)
hold on
xlabel(‘eta ‘, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘G(eta) ‘, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
hold off
% Plotting of theta
figure(3)
plot(x, y(7,:), ‘linewidth’, 1)
hold on
xlabel(‘eta’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘theta(eta)’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
hold off
% Residual of the boundary conditions
function res = bc2D(y0, yinf)
res = [y0(1);yinf(1); y0(4); yinf(4);y0(5)-Rew; yinf(5)-Red;y0(7)-1; yinf(7)];
end
% System of First Order ODEs
function dydx = bvp2D(eta, y)
yy1 = (-(1+eta^2)*((10*A1*eta+A2*eta*y(1)-A2*y(4))*y(3))-3*(2*A1+7*A1*(eta^2)+A2*(2*eta^2+1)*y(1)-A2*eta*y(4))*y(2)-2*A2*y(5)*y(6)-3*(A1+A2*y(1))*y(4)+A3*M*y(2)-A4*Grt*y(8))/(A1*(1+eta^2)^2);
yy2 = eta*y(2);
yy3 = (-3*A1*eta*y(6)-A2*(eta*y(1)-y(4))*y(6)+A3*M*y(5))/(A1*(eta^2+1));
yy4 = ((A5+4/3*R)*((eta*((2*n)-1))*y(8)+n^2*y(7))-A3*Pr*M*Ec*(y(1)^2+y(5)^2)-Pr*Q*y(7)+A6*Pr*(y(4)*y(8)+n*y(1)*y(7)-eta*y(1)*y(8)))/(A5+4/3*R)*(1+eta^2);
dydx = [y(2); y(3); yy1; yy2; y(6); yy3; y(8); yy4];
end
end
The code is running but I am unable to get the graph what i have attached for radial velocity and azimuthal velocity conedisk MATLAB Answers — New Questions
运行循环或者整段代码的时候报错“未定义函数或变量”,但单独执行该段代码会将添加路径的数据赋值给变量,并且相同路径的上一个变量的赋值就正常
data_num=1;
for num1=1:data_num
switch num1
case 1
s4=’F:datasourc1.txt’;
sou4=load(strcat(s4));
pd1_1=sou4(1:2:end,:);
pd2_1=sou4(2:2:end,:);
case 2
s5=’F:datasource1.txt’;
sou5=load(strcat(s5));
pd1_2=sou5(1:2:end,:);
pd2_2=sou5(2:2:end,:);
otherwise
disp(‘input data error’)
end
NOTE: 只截取了程序的出错部分,无法在网站运行,还请各位论坛大神帮忙解答debug
报错:未定义函数或变量‘pd1_2’data_num=1;
for num1=1:data_num
switch num1
case 1
s4=’F:datasourc1.txt’;
sou4=load(strcat(s4));
pd1_1=sou4(1:2:end,:);
pd2_1=sou4(2:2:end,:);
case 2
s5=’F:datasource1.txt’;
sou5=load(strcat(s5));
pd1_2=sou5(1:2:end,:);
pd2_2=sou5(2:2:end,:);
otherwise
disp(‘input data error’)
end
NOTE: 只截取了程序的出错部分,无法在网站运行,还请各位论坛大神帮忙解答debug
报错:未定义函数或变量‘pd1_2′ data_num=1;
for num1=1:data_num
switch num1
case 1
s4=’F:datasourc1.txt’;
sou4=load(strcat(s4));
pd1_1=sou4(1:2:end,:);
pd2_1=sou4(2:2:end,:);
case 2
s5=’F:datasource1.txt’;
sou5=load(strcat(s5));
pd1_2=sou5(1:2:end,:);
pd2_2=sou5(2:2:end,:);
otherwise
disp(‘input data error’)
end
NOTE: 只截取了程序的出错部分,无法在网站运行,还请各位论坛大神帮忙解答debug
报错:未定义函数或变量‘pd1_2′ 数据调用,变量赋值 MATLAB Answers — New Questions
projcrs function is not working
Hello, I cannot use projcrs somehow, I need it to extract some json georef data and make a latitude/longitude map so I can extract specific pixels over my .tiff file. I am reading my json file and I was trying to do
utmZone = ‘32634’;
utmProjection = projcrs(utmZone);
[lat, lon] = projfwd(utmProjection, xCoords, yCoords);
But projcrs fails. I tried with many format and other numbers.
Is there something I may be missing?
>> p = projcrs(28992);
Error: File: validateLengthUnit.m Line: 1 Column: 1
Invalid text character. Check for unsupported symbol, invisible character, or pasting of non-ASCII characters.
Error in referenceEllipsoid/epsgEllipsoid (line 481)
self.pLengthUnit = validateLengthUnit(uom_name);
Error in referenceEllipsoid (line 288)
self = self.epsgEllipsoid(code);
Error in geocrs/setPropertiesFromCRSInput (line 212)
obj.Spheroid = referenceEllipsoid(ellipsoidcode);
Error in geocrs (line 71)
obj = setPropertiesFromCRSInput(obj, crs);
Error in projcrs/setPropertiesFromCRSInput (line 498)
obj.GeographicCRS = geocrs(gcrscode,"Authority",crsinfo.GCRSAuthority);
Error in projcrs (line 89)
obj = setPropertiesFromCRSInput(obj, crs);Hello, I cannot use projcrs somehow, I need it to extract some json georef data and make a latitude/longitude map so I can extract specific pixels over my .tiff file. I am reading my json file and I was trying to do
utmZone = ‘32634’;
utmProjection = projcrs(utmZone);
[lat, lon] = projfwd(utmProjection, xCoords, yCoords);
But projcrs fails. I tried with many format and other numbers.
Is there something I may be missing?
>> p = projcrs(28992);
Error: File: validateLengthUnit.m Line: 1 Column: 1
Invalid text character. Check for unsupported symbol, invisible character, or pasting of non-ASCII characters.
Error in referenceEllipsoid/epsgEllipsoid (line 481)
self.pLengthUnit = validateLengthUnit(uom_name);
Error in referenceEllipsoid (line 288)
self = self.epsgEllipsoid(code);
Error in geocrs/setPropertiesFromCRSInput (line 212)
obj.Spheroid = referenceEllipsoid(ellipsoidcode);
Error in geocrs (line 71)
obj = setPropertiesFromCRSInput(obj, crs);
Error in projcrs/setPropertiesFromCRSInput (line 498)
obj.GeographicCRS = geocrs(gcrscode,"Authority",crsinfo.GCRSAuthority);
Error in projcrs (line 89)
obj = setPropertiesFromCRSInput(obj, crs); Hello, I cannot use projcrs somehow, I need it to extract some json georef data and make a latitude/longitude map so I can extract specific pixels over my .tiff file. I am reading my json file and I was trying to do
utmZone = ‘32634’;
utmProjection = projcrs(utmZone);
[lat, lon] = projfwd(utmProjection, xCoords, yCoords);
But projcrs fails. I tried with many format and other numbers.
Is there something I may be missing?
>> p = projcrs(28992);
Error: File: validateLengthUnit.m Line: 1 Column: 1
Invalid text character. Check for unsupported symbol, invisible character, or pasting of non-ASCII characters.
Error in referenceEllipsoid/epsgEllipsoid (line 481)
self.pLengthUnit = validateLengthUnit(uom_name);
Error in referenceEllipsoid (line 288)
self = self.epsgEllipsoid(code);
Error in geocrs/setPropertiesFromCRSInput (line 212)
obj.Spheroid = referenceEllipsoid(ellipsoidcode);
Error in geocrs (line 71)
obj = setPropertiesFromCRSInput(obj, crs);
Error in projcrs/setPropertiesFromCRSInput (line 498)
obj.GeographicCRS = geocrs(gcrscode,"Authority",crsinfo.GCRSAuthority);
Error in projcrs (line 89)
obj = setPropertiesFromCRSInput(obj, crs); image processing MATLAB Answers — New Questions
MCR dll 7.16 32-bit 64-bit Windows 7
Hi.
I use R2011B on a 32-bit installation on Windows 7. Where can I find the files for the MCR dll that I can send to customers so they can run compiled scripts.
Are their different 32-bit and 64-bit versions?
I knew how to do this for R2007B on 32-bit but now I am stuck.
I can install 64-bit if it helps but just dont use it for other reasons.Hi.
I use R2011B on a 32-bit installation on Windows 7. Where can I find the files for the MCR dll that I can send to customers so they can run compiled scripts.
Are their different 32-bit and 64-bit versions?
I knew how to do this for R2007B on 32-bit but now I am stuck.
I can install 64-bit if it helps but just dont use it for other reasons. Hi.
I use R2011B on a 32-bit installation on Windows 7. Where can I find the files for the MCR dll that I can send to customers so they can run compiled scripts.
Are their different 32-bit and 64-bit versions?
I knew how to do this for R2007B on 32-bit but now I am stuck.
I can install 64-bit if it helps but just dont use it for other reasons. mcr MATLAB Answers — New Questions
App designer creates a new function inside another function where a parfor loop exists
As the title suggests, it is created in an existing function with a parfor loop when creating a new function in App Designer. Commenting out the parfor loop creates the new function as normal.As the title suggests, it is created in an existing function with a parfor loop when creating a new function in App Designer. Commenting out the parfor loop creates the new function as normal. As the title suggests, it is created in an existing function with a parfor loop when creating a new function in App Designer. Commenting out the parfor loop creates the new function as normal. app designer, parfor MATLAB Answers — New Questions
How to log the data in the workspace without modifying the content of the for loop?
I am currently using MATLAB 2022a.
I have a for loop (let’s call this for loop LOOP_A) doing some calculation and each calculation is depending on some values from the previous loop.
Without editting too much of the content of LOOP_A, I want to log those variables at the end of each loop.
I’m thinking about having another for loop (let’s call this one LOOP_B) that log the data in the workspace for each loop of LOOP_A till the entire execution of the LOOP_A is finished.
Here is what I would like to have:
% Repeat the following till all loops are finished:
% LOOP_A:
% Pause after one iteration
% Send data from workspace to LOOP_B
% Wait till LOOP_B send "good to go" signal if not finished
% LOOP_B:
% Receive data from LOOP_A
% Store the data
% Send "good to go" signal to LOOP_A
% LOOP_A:
% Continue running for one iteration
% Send data from workspace to LOOP_B
% Wait till LOOP_B send "good to go" signal if not finished
% …
Is there a way I can do that?I am currently using MATLAB 2022a.
I have a for loop (let’s call this for loop LOOP_A) doing some calculation and each calculation is depending on some values from the previous loop.
Without editting too much of the content of LOOP_A, I want to log those variables at the end of each loop.
I’m thinking about having another for loop (let’s call this one LOOP_B) that log the data in the workspace for each loop of LOOP_A till the entire execution of the LOOP_A is finished.
Here is what I would like to have:
% Repeat the following till all loops are finished:
% LOOP_A:
% Pause after one iteration
% Send data from workspace to LOOP_B
% Wait till LOOP_B send "good to go" signal if not finished
% LOOP_B:
% Receive data from LOOP_A
% Store the data
% Send "good to go" signal to LOOP_A
% LOOP_A:
% Continue running for one iteration
% Send data from workspace to LOOP_B
% Wait till LOOP_B send "good to go" signal if not finished
% …
Is there a way I can do that? I am currently using MATLAB 2022a.
I have a for loop (let’s call this for loop LOOP_A) doing some calculation and each calculation is depending on some values from the previous loop.
Without editting too much of the content of LOOP_A, I want to log those variables at the end of each loop.
I’m thinking about having another for loop (let’s call this one LOOP_B) that log the data in the workspace for each loop of LOOP_A till the entire execution of the LOOP_A is finished.
Here is what I would like to have:
% Repeat the following till all loops are finished:
% LOOP_A:
% Pause after one iteration
% Send data from workspace to LOOP_B
% Wait till LOOP_B send "good to go" signal if not finished
% LOOP_B:
% Receive data from LOOP_A
% Store the data
% Send "good to go" signal to LOOP_A
% LOOP_A:
% Continue running for one iteration
% Send data from workspace to LOOP_B
% Wait till LOOP_B send "good to go" signal if not finished
% …
Is there a way I can do that? matlab MATLAB Answers — New Questions
Why am I continuously prompted to activate when I try to launch MATLAB?
I am trying to activate and use MATLAB. Every time I start MATLAB, it prompts me to activate, even though I complete the process and it states activation is complete each time.
Why am I continuously prompted to activate when I try to launch MATLAB?I am trying to activate and use MATLAB. Every time I start MATLAB, it prompts me to activate, even though I complete the process and it states activation is complete each time.
Why am I continuously prompted to activate when I try to launch MATLAB? I am trying to activate and use MATLAB. Every time I start MATLAB, it prompts me to activate, even though I complete the process and it states activation is complete each time.
Why am I continuously prompted to activate when I try to launch MATLAB? matlab, license, installation, key, activation, loop, actloop, conact MATLAB Answers — New Questions
I need to write a code to find numbers divisible by 7 and multiples of 5 from 1500:2700. How do I preallocate line 4 for speed and is my code the most efficient way to solve
result = [];
for num = 1500:2700
if mod(num, 7) == 0 && mod(num, 5) == 0
result = [result, num];
end
end
disp(‘Numbers between 1500 and 2700 that are divisible by 7 and multiples of 5:’);
disp(result);result = [];
for num = 1500:2700
if mod(num, 7) == 0 && mod(num, 5) == 0
result = [result, num];
end
end
disp(‘Numbers between 1500 and 2700 that are divisible by 7 and multiples of 5:’);
disp(result); result = [];
for num = 1500:2700
if mod(num, 7) == 0 && mod(num, 5) == 0
result = [result, num];
end
end
disp(‘Numbers between 1500 and 2700 that are divisible by 7 and multiples of 5:’);
disp(result); hw MATLAB Answers — New Questions
How to check/map simulink data set is matching model’s inports programmatically?
I have some simulink dataset stored in a lot of mat files.
Is there a way to check those dataset is still matching the model’s inports?
I know I can probably use Root Inport Mapper to check it manually, but I would like to know how to do that programmatically.
ThanksI have some simulink dataset stored in a lot of mat files.
Is there a way to check those dataset is still matching the model’s inports?
I know I can probably use Root Inport Mapper to check it manually, but I would like to know how to do that programmatically.
Thanks I have some simulink dataset stored in a lot of mat files.
Is there a way to check those dataset is still matching the model’s inports?
I know I can probably use Root Inport Mapper to check it manually, but I would like to know how to do that programmatically.
Thanks root inport mapper, simulink MATLAB Answers — New Questions
List Arduinos and connect to multiple Simulink
Hi,
I have 2 questions. 1 is about the com port and 2 is about the setting up the simulink via code.
So I found out that 2024A version has the function to list the Arduino using arduinolist – List available Arduino hardware – MATLAB (mathworks.com) this function.
However, I am currently unable to get 2024a but has 2023b version so I am looking for some suggestions how to make this list automatically so I can utilize. My start idea is to list the comport using the serialportlist("available") to obtain the comport that are connected which was successful but couldn’t find a way to obtain the information from the comport to detect what which Arduino is connected to which comport.
Can anyone give me some suggestions?
The second question is about how to connect the Simulink to these each Arduino.
I am able to open the Simulink using the open_system But couldn’t get each Simulink to connect to each Arduino. Is there a way to code so that the specific Simulink can connect to a specific Arduino. Any ideas please?
Thanks!Hi,
I have 2 questions. 1 is about the com port and 2 is about the setting up the simulink via code.
So I found out that 2024A version has the function to list the Arduino using arduinolist – List available Arduino hardware – MATLAB (mathworks.com) this function.
However, I am currently unable to get 2024a but has 2023b version so I am looking for some suggestions how to make this list automatically so I can utilize. My start idea is to list the comport using the serialportlist("available") to obtain the comport that are connected which was successful but couldn’t find a way to obtain the information from the comport to detect what which Arduino is connected to which comport.
Can anyone give me some suggestions?
The second question is about how to connect the Simulink to these each Arduino.
I am able to open the Simulink using the open_system But couldn’t get each Simulink to connect to each Arduino. Is there a way to code so that the specific Simulink can connect to a specific Arduino. Any ideas please?
Thanks! Hi,
I have 2 questions. 1 is about the com port and 2 is about the setting up the simulink via code.
So I found out that 2024A version has the function to list the Arduino using arduinolist – List available Arduino hardware – MATLAB (mathworks.com) this function.
However, I am currently unable to get 2024a but has 2023b version so I am looking for some suggestions how to make this list automatically so I can utilize. My start idea is to list the comport using the serialportlist("available") to obtain the comport that are connected which was successful but couldn’t find a way to obtain the information from the comport to detect what which Arduino is connected to which comport.
Can anyone give me some suggestions?
The second question is about how to connect the Simulink to these each Arduino.
I am able to open the Simulink using the open_system But couldn’t get each Simulink to connect to each Arduino. Is there a way to code so that the specific Simulink can connect to a specific Arduino. Any ideas please?
Thanks! arduino, simulink, appdesigner MATLAB Answers — New Questions
Change grid cell size and interpolate values from old grid into new grid.
I currently have a bathymetric grid that is 1504 m x 1217 m, with a matrix size of 356×583. This means the grid cell size is roughly 2.58 x 3.42 and is therefore slightly rectangular.
I would like to create a grid that is a square 3 x 3 resolution to cover this domain, which will be a 405 x 501 matrix (1215m x 1503m), and interpolate the values of the old matrix into the new one. I have heard that I can use interp2, or griddata to do this, but I’m not 100% sure where to start. Could someone give me a couplke of pointers to get me on the way to achieving this?
Thanks!I currently have a bathymetric grid that is 1504 m x 1217 m, with a matrix size of 356×583. This means the grid cell size is roughly 2.58 x 3.42 and is therefore slightly rectangular.
I would like to create a grid that is a square 3 x 3 resolution to cover this domain, which will be a 405 x 501 matrix (1215m x 1503m), and interpolate the values of the old matrix into the new one. I have heard that I can use interp2, or griddata to do this, but I’m not 100% sure where to start. Could someone give me a couplke of pointers to get me on the way to achieving this?
Thanks! I currently have a bathymetric grid that is 1504 m x 1217 m, with a matrix size of 356×583. This means the grid cell size is roughly 2.58 x 3.42 and is therefore slightly rectangular.
I would like to create a grid that is a square 3 x 3 resolution to cover this domain, which will be a 405 x 501 matrix (1215m x 1503m), and interpolate the values of the old matrix into the new one. I have heard that I can use interp2, or griddata to do this, but I’m not 100% sure where to start. Could someone give me a couplke of pointers to get me on the way to achieving this?
Thanks! grid, matrix, domain, resolution MATLAB Answers — New Questions
Can’t set the modeling options parameter of the simscape battery block using set_param function
How can I programmatically set the modeling option parameter for a Simscape Battery block in MATLAB to "Instrumented | Show thermal port" to display both the SOC and thermal ports?
I tried using get_param to retrieve the parameters of the battery block, but I couldn’t find any related to the modeling options (SOC or thermal ports). Is there a way to programmatically enable these ports or set these parameters through a MATLAB script?How can I programmatically set the modeling option parameter for a Simscape Battery block in MATLAB to "Instrumented | Show thermal port" to display both the SOC and thermal ports?
I tried using get_param to retrieve the parameters of the battery block, but I couldn’t find any related to the modeling options (SOC or thermal ports). Is there a way to programmatically enable these ports or set these parameters through a MATLAB script? How can I programmatically set the modeling option parameter for a Simscape Battery block in MATLAB to "Instrumented | Show thermal port" to display both the SOC and thermal ports?
I tried using get_param to retrieve the parameters of the battery block, but I couldn’t find any related to the modeling options (SOC or thermal ports). Is there a way to programmatically enable these ports or set these parameters through a MATLAB script? simulink, simscape, battery, modeling options, programmatic modeling MATLAB Answers — New Questions
Exporting Graphs from Matlab App in PNG or JPG
I’m using an app to fit some experimental data to model. The app wasn’t written by myself. After fitting, few different graphs are shown with the results. I don’t see the option to export these graphs in PNG or JPG or any other format for that matter inside the app window. Do you know how can one export graphs from this Matlab app.
Here is the app window shown. Usually, with graphs, there is an export button on the axes toolbar. However, none exist here.I’m using an app to fit some experimental data to model. The app wasn’t written by myself. After fitting, few different graphs are shown with the results. I don’t see the option to export these graphs in PNG or JPG or any other format for that matter inside the app window. Do you know how can one export graphs from this Matlab app.
Here is the app window shown. Usually, with graphs, there is an export button on the axes toolbar. However, none exist here. I’m using an app to fit some experimental data to model. The app wasn’t written by myself. After fitting, few different graphs are shown with the results. I don’t see the option to export these graphs in PNG or JPG or any other format for that matter inside the app window. Do you know how can one export graphs from this Matlab app.
Here is the app window shown. Usually, with graphs, there is an export button on the axes toolbar. However, none exist here. graph, export MATLAB Answers — New Questions
How can I write data to a text file in a user-specified location that is already populated with a standard header?
Currently, I am working on an app that can successfully write 4 columns of data to a text file in a user-defined file location, at the push of a button. I am accomplishing this task using the following code:
% Button pushed function: ExporttotxtButton
function ExporttotxtButtonPushed(app, event)
[fn,pn] = uiputfile(‘.rdf’,’RoadProfile_bumpy_fl.rdf’,’RoadProfile_bumpy_fl.rdf’);
if isnumeric(fn) % user canceled
return % return early
end
% write the table to the user-specified file
writematrix(app.UITable.Data,fullfile(pn,fn),’Delimiter’,’tab’,’FileType’,’text’);
However, I have a very long string of text (about 47 lines of text…not included here to save space) that I would like to include as a header in the generated text file. The goal is to have the end result be a text file that already has the header populated with a standard 47 lines of text, and then write the matrix data below the header as I am already doing. I have tried using the following:
fprintf(fullfile(pn,fn),’%sn’,[‘long_string_of_text..’ …
‘creating new line each timen’…]
But, this doesn’t seem to work. Any help would be much appreciated. I can post the full text that I want to include in the header if that is necessary. Thank you.Currently, I am working on an app that can successfully write 4 columns of data to a text file in a user-defined file location, at the push of a button. I am accomplishing this task using the following code:
% Button pushed function: ExporttotxtButton
function ExporttotxtButtonPushed(app, event)
[fn,pn] = uiputfile(‘.rdf’,’RoadProfile_bumpy_fl.rdf’,’RoadProfile_bumpy_fl.rdf’);
if isnumeric(fn) % user canceled
return % return early
end
% write the table to the user-specified file
writematrix(app.UITable.Data,fullfile(pn,fn),’Delimiter’,’tab’,’FileType’,’text’);
However, I have a very long string of text (about 47 lines of text…not included here to save space) that I would like to include as a header in the generated text file. The goal is to have the end result be a text file that already has the header populated with a standard 47 lines of text, and then write the matrix data below the header as I am already doing. I have tried using the following:
fprintf(fullfile(pn,fn),’%sn’,[‘long_string_of_text..’ …
‘creating new line each timen’…]
But, this doesn’t seem to work. Any help would be much appreciated. I can post the full text that I want to include in the header if that is necessary. Thank you. Currently, I am working on an app that can successfully write 4 columns of data to a text file in a user-defined file location, at the push of a button. I am accomplishing this task using the following code:
% Button pushed function: ExporttotxtButton
function ExporttotxtButtonPushed(app, event)
[fn,pn] = uiputfile(‘.rdf’,’RoadProfile_bumpy_fl.rdf’,’RoadProfile_bumpy_fl.rdf’);
if isnumeric(fn) % user canceled
return % return early
end
% write the table to the user-specified file
writematrix(app.UITable.Data,fullfile(pn,fn),’Delimiter’,’tab’,’FileType’,’text’);
However, I have a very long string of text (about 47 lines of text…not included here to save space) that I would like to include as a header in the generated text file. The goal is to have the end result be a text file that already has the header populated with a standard 47 lines of text, and then write the matrix data below the header as I am already doing. I have tried using the following:
fprintf(fullfile(pn,fn),’%sn’,[‘long_string_of_text..’ …
‘creating new line each timen’…]
But, this doesn’t seem to work. Any help would be much appreciated. I can post the full text that I want to include in the header if that is necessary. Thank you. appdesigner MATLAB Answers — New Questions
Simulink model parameter update and observations at discrete times
I have a Simulink model M which includes a parameter p. Assume that I want to simulate M over the the time period [0, T]. Also assume that I get an output y from the model M.
Now consider discrete time points [0 t_1, t_2, …, t_n] in the time interval [0, T]. At each t_i I want to change p in the model and want to get the value of y.
How can I do this?I have a Simulink model M which includes a parameter p. Assume that I want to simulate M over the the time period [0, T]. Also assume that I get an output y from the model M.
Now consider discrete time points [0 t_1, t_2, …, t_n] in the time interval [0, T]. At each t_i I want to change p in the model and want to get the value of y.
How can I do this? I have a Simulink model M which includes a parameter p. Assume that I want to simulate M over the the time period [0, T]. Also assume that I get an output y from the model M.
Now consider discrete time points [0 t_1, t_2, …, t_n] in the time interval [0, T]. At each t_i I want to change p in the model and want to get the value of y.
How can I do this? simulink MATLAB Answers — New Questions
silly error in trainnet network design
received following errors – for seemingly straight forward command:
> net = trainnet(data1, class1, net_1, "crossentropy", options);
Error Number of observations in predictors (1) and targets (1071) must match.
Check that the data and network are consistent.
This is odd because both the training and validation data/class are matching size 1071 X 140 and 1071 X 1. Could you please advise. Similarly validation in options have compatiable digmensions. weird.received following errors – for seemingly straight forward command:
> net = trainnet(data1, class1, net_1, "crossentropy", options);
Error Number of observations in predictors (1) and targets (1071) must match.
Check that the data and network are consistent.
This is odd because both the training and validation data/class are matching size 1071 X 140 and 1071 X 1. Could you please advise. Similarly validation in options have compatiable digmensions. weird. received following errors – for seemingly straight forward command:
> net = trainnet(data1, class1, net_1, "crossentropy", options);
Error Number of observations in predictors (1) and targets (1071) must match.
Check that the data and network are consistent.
This is odd because both the training and validation data/class are matching size 1071 X 140 and 1071 X 1. Could you please advise. Similarly validation in options have compatiable digmensions. weird. trainnet, deep learning MATLAB Answers — New Questions
Best computer specifications for fast Matlab numerical simulations/integrations?
I have an old and slow PC, and it’s time to consider buying a new one. I need it for writing simulations involving heavy numerical integrations of differential equations with high precision, which take a lot of computing time. I’m wondering what kind of specifications I should look for. I assume the most powerful processor and lots of memory, but do you have any other suggestions?I have an old and slow PC, and it’s time to consider buying a new one. I need it for writing simulations involving heavy numerical integrations of differential equations with high precision, which take a lot of computing time. I’m wondering what kind of specifications I should look for. I assume the most powerful processor and lots of memory, but do you have any other suggestions? I have an old and slow PC, and it’s time to consider buying a new one. I need it for writing simulations involving heavy numerical integrations of differential equations with high precision, which take a lot of computing time. I’m wondering what kind of specifications I should look for. I assume the most powerful processor and lots of memory, but do you have any other suggestions? fast pc, speed MATLAB Answers — New Questions
Error: Unable to open file for writing. Check write permission.
I´m doing a code to generate a system composer report with sequence diagrams, but when i run the code, i get the error: Unable to open file ‘C:UsersuserOneDriveDocumentsMATLABimage.png for writing. Check write permission. I checked that path and i do have writing permission, and i try running matlab as admin, but i get the same error. The tricky part is, if I run a simple code using the imwrite comand to save an image in that path (before running the report generator code i have), it works well and it writes an image there, but as soon as i run the repor generator code, i get the error, and if again, try to use the imwrite command (that previously worked) it throws the same error that said i don´t have write permission, but it had worked moments ago. Also, in the report generator code, in anypart of the code I specifed that i want to save the images in that specific path, matlab uses that path by default.
This is the report generator code:
import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*
import mlreportgen.dom.*
import mlreportgen.utils.*
import systemcomposer.query.*
import systemcomposer.rptgen.finder.*
rpt = slreportgen.report.Report(‘OutputPath’, ‘FullArchitecture’, …
‘CompileModelBeforeReporting’, false);
model = systemcomposer.loadModel(modelFileName);
if isempty(model)
error(‘Model could not be loaded: %s’, modelFileName);
end
seqDiagrams = model.getInteractions;
if isempty(seqDiagrams)
warning(‘No sequence diagrams found in the model: %s’, modelFileName);
return; % Exit if there are no diagrams
end
seqChapter = Chapter("Title", "Sequence Diagrams");
Sect = Section("Title", model.Name);
add(seqChapter, Sect);
try
% Loop through each sequence diagram and add it to the report
for i = 1:length(seqDiagrams)
seqDiagram = seqDiagrams(i);
% Create a SequenceDiagram reporter for each diagram
seqReporter = systemcomposer.rptgen.report.SequenceDiagram("Name", …
seqDiagram.Name, "ModelName", model.Name);
seqSect = Section("Title", seqDiagram.Name);
add(seqSect, seqReporter);
add(Sect, seqSect);
end
% Add the chapter to the report
add(rpt, seqChapter);
catch ME
fprintf(‘Error encountered: %sn’, ME.message);
end
% Finally, close and view or save the report (depending on platform)
close(rpt);I´m doing a code to generate a system composer report with sequence diagrams, but when i run the code, i get the error: Unable to open file ‘C:UsersuserOneDriveDocumentsMATLABimage.png for writing. Check write permission. I checked that path and i do have writing permission, and i try running matlab as admin, but i get the same error. The tricky part is, if I run a simple code using the imwrite comand to save an image in that path (before running the report generator code i have), it works well and it writes an image there, but as soon as i run the repor generator code, i get the error, and if again, try to use the imwrite command (that previously worked) it throws the same error that said i don´t have write permission, but it had worked moments ago. Also, in the report generator code, in anypart of the code I specifed that i want to save the images in that specific path, matlab uses that path by default.
This is the report generator code:
import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*
import mlreportgen.dom.*
import mlreportgen.utils.*
import systemcomposer.query.*
import systemcomposer.rptgen.finder.*
rpt = slreportgen.report.Report(‘OutputPath’, ‘FullArchitecture’, …
‘CompileModelBeforeReporting’, false);
model = systemcomposer.loadModel(modelFileName);
if isempty(model)
error(‘Model could not be loaded: %s’, modelFileName);
end
seqDiagrams = model.getInteractions;
if isempty(seqDiagrams)
warning(‘No sequence diagrams found in the model: %s’, modelFileName);
return; % Exit if there are no diagrams
end
seqChapter = Chapter("Title", "Sequence Diagrams");
Sect = Section("Title", model.Name);
add(seqChapter, Sect);
try
% Loop through each sequence diagram and add it to the report
for i = 1:length(seqDiagrams)
seqDiagram = seqDiagrams(i);
% Create a SequenceDiagram reporter for each diagram
seqReporter = systemcomposer.rptgen.report.SequenceDiagram("Name", …
seqDiagram.Name, "ModelName", model.Name);
seqSect = Section("Title", seqDiagram.Name);
add(seqSect, seqReporter);
add(Sect, seqSect);
end
% Add the chapter to the report
add(rpt, seqChapter);
catch ME
fprintf(‘Error encountered: %sn’, ME.message);
end
% Finally, close and view or save the report (depending on platform)
close(rpt); I´m doing a code to generate a system composer report with sequence diagrams, but when i run the code, i get the error: Unable to open file ‘C:UsersuserOneDriveDocumentsMATLABimage.png for writing. Check write permission. I checked that path and i do have writing permission, and i try running matlab as admin, but i get the same error. The tricky part is, if I run a simple code using the imwrite comand to save an image in that path (before running the report generator code i have), it works well and it writes an image there, but as soon as i run the repor generator code, i get the error, and if again, try to use the imwrite command (that previously worked) it throws the same error that said i don´t have write permission, but it had worked moments ago. Also, in the report generator code, in anypart of the code I specifed that i want to save the images in that specific path, matlab uses that path by default.
This is the report generator code:
import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*
import mlreportgen.dom.*
import mlreportgen.utils.*
import systemcomposer.query.*
import systemcomposer.rptgen.finder.*
rpt = slreportgen.report.Report(‘OutputPath’, ‘FullArchitecture’, …
‘CompileModelBeforeReporting’, false);
model = systemcomposer.loadModel(modelFileName);
if isempty(model)
error(‘Model could not be loaded: %s’, modelFileName);
end
seqDiagrams = model.getInteractions;
if isempty(seqDiagrams)
warning(‘No sequence diagrams found in the model: %s’, modelFileName);
return; % Exit if there are no diagrams
end
seqChapter = Chapter("Title", "Sequence Diagrams");
Sect = Section("Title", model.Name);
add(seqChapter, Sect);
try
% Loop through each sequence diagram and add it to the report
for i = 1:length(seqDiagrams)
seqDiagram = seqDiagrams(i);
% Create a SequenceDiagram reporter for each diagram
seqReporter = systemcomposer.rptgen.report.SequenceDiagram("Name", …
seqDiagram.Name, "ModelName", model.Name);
seqSect = Section("Title", seqDiagram.Name);
add(seqSect, seqReporter);
add(Sect, seqSect);
end
% Add the chapter to the report
add(rpt, seqChapter);
catch ME
fprintf(‘Error encountered: %sn’, ME.message);
end
% Finally, close and view or save the report (depending on platform)
close(rpt); system composer, sequence diagram, reports MATLAB Answers — New Questions
Generalised solution to a n-order system of equations
I want to solve (for the first term) of a system of n equations, in terms of n. How should I do it?
Essentially I want to solve for a_1 in terms of n:
(This holds for all k=1…n).
How do I code this in MatLab? I always meet a lot of errors complaining about the general formula. Thank you.I want to solve (for the first term) of a system of n equations, in terms of n. How should I do it?
Essentially I want to solve for a_1 in terms of n:
(This holds for all k=1…n).
How do I code this in MatLab? I always meet a lot of errors complaining about the general formula. Thank you. I want to solve (for the first term) of a system of n equations, in terms of n. How should I do it?
Essentially I want to solve for a_1 in terms of n:
(This holds for all k=1…n).
How do I code this in MatLab? I always meet a lot of errors complaining about the general formula. Thank you. matlab, mathematics, matrix, equation MATLAB Answers — New Questions