Category: Matlab
Category Archives: Matlab
How to plot different grouped boxplots in a shared x axis with different dimensions that are inconsistent?
Hi! I want to ask how to plot this 3 different grouped boxplots in a shared x-axis? because i plan to see the differences between them and add another secondary label to it. I want to make something like in the picture (attached), but I don’t know how to make it work because i keep on having an error that says "dimensions of arrays being concatenated are not consistent".
close all; clear all; clc;
%————————————————————————–
% Data from 1mm
a = load ("All-1mm.txt");
b = load ("Origin-1mm.txt");
% Data from 1mm
c = load ("All-2mm.txt");
d = load ("Origin-2mm.txt");
% Data from 1mm
e = load ("All-3mm.txt");
f = load ("Origin-3mm.txt");
%————————————————————————–
figure
boxplot (a, b);
ylabel ("Displacement (m)");
title(‘1 mm Displacement’);
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = ‘none’; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {‘X’, ‘Y’, ‘Z’, ‘Combined’}; % Assign secondary labels
figure
boxplot (c, d);
ylabel ("Displacement (m)");
title(‘2 mm Displacement’);
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = ‘none’; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {‘X’, ‘Y’, ‘Z’, ‘Combined’}; % Assign secondary labels
figure
boxplot (e, f);
ylabel ("Displacement (m)");
title(‘3 mm Displacement’);
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = ‘none’; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {‘X’, ‘Y’, ‘Z’, ‘Combined’}; % Assign secondary labelsHi! I want to ask how to plot this 3 different grouped boxplots in a shared x-axis? because i plan to see the differences between them and add another secondary label to it. I want to make something like in the picture (attached), but I don’t know how to make it work because i keep on having an error that says "dimensions of arrays being concatenated are not consistent".
close all; clear all; clc;
%————————————————————————–
% Data from 1mm
a = load ("All-1mm.txt");
b = load ("Origin-1mm.txt");
% Data from 1mm
c = load ("All-2mm.txt");
d = load ("Origin-2mm.txt");
% Data from 1mm
e = load ("All-3mm.txt");
f = load ("Origin-3mm.txt");
%————————————————————————–
figure
boxplot (a, b);
ylabel ("Displacement (m)");
title(‘1 mm Displacement’);
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = ‘none’; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {‘X’, ‘Y’, ‘Z’, ‘Combined’}; % Assign secondary labels
figure
boxplot (c, d);
ylabel ("Displacement (m)");
title(‘2 mm Displacement’);
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = ‘none’; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {‘X’, ‘Y’, ‘Z’, ‘Combined’}; % Assign secondary labels
figure
boxplot (e, f);
ylabel ("Displacement (m)");
title(‘3 mm Displacement’);
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = ‘none’; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {‘X’, ‘Y’, ‘Z’, ‘Combined’}; % Assign secondary labels Hi! I want to ask how to plot this 3 different grouped boxplots in a shared x-axis? because i plan to see the differences between them and add another secondary label to it. I want to make something like in the picture (attached), but I don’t know how to make it work because i keep on having an error that says "dimensions of arrays being concatenated are not consistent".
close all; clear all; clc;
%————————————————————————–
% Data from 1mm
a = load ("All-1mm.txt");
b = load ("Origin-1mm.txt");
% Data from 1mm
c = load ("All-2mm.txt");
d = load ("Origin-2mm.txt");
% Data from 1mm
e = load ("All-3mm.txt");
f = load ("Origin-3mm.txt");
%————————————————————————–
figure
boxplot (a, b);
ylabel ("Displacement (m)");
title(‘1 mm Displacement’);
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = ‘none’; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {‘X’, ‘Y’, ‘Z’, ‘Combined’}; % Assign secondary labels
figure
boxplot (c, d);
ylabel ("Displacement (m)");
title(‘2 mm Displacement’);
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = ‘none’; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {‘X’, ‘Y’, ‘Z’, ‘Combined’}; % Assign secondary labels
figure
boxplot (e, f);
ylabel ("Displacement (m)");
title(‘3 mm Displacement’);
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = ‘none’; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {‘X’, ‘Y’, ‘Z’, ‘Combined’}; % Assign secondary labels matlab, boxplot, multiple boxplot MATLAB Answers — New Questions
how to add booster converter in circuit
Hii, I want to add booster converter in my LLC resonant porposed model. Can anyone help me with connections?Hii, I want to add booster converter in my LLC resonant porposed model. Can anyone help me with connections? Hii, I want to add booster converter in my LLC resonant porposed model. Can anyone help me with connections? boost converter, matlab, llc resonant converter MATLAB Answers — New Questions
Using MATLAB to write to Arduino serial monitor to control stepper motor
I am currently building a positioner that will move a probe in the x and y direction through the use of three stepper motors and a RAMBo 1.1b board. I have written code through the Arduino IDE that allows me to do so through inputting options in the serial monitor. My goal is to use MATLAB to build a GUI, and write user inputs from MATLAB to the serial monitor. However, I have not figured out how to write to the serial monitor.
Here is my code that I have uploaded to the board (important code is in the loop):
// These define all the pin outs for the Rambo board
#define ELECTRONICS "RAMBo11b"
#define stepPinX1 37//function D37 , port PD7
#define dirPinX1 48//function D48 , port PL1
#define X_MIN_PIN 12//function PWM12, port PB6
#define X_MAX_PIN 24//function D24 , port PA2
#define enPinX1 29//function D29 , port PA7
#define X_MS1_PIN 40//function D40 , port PG1
#define X_MS2_PIN 41//function D41 , port PG0
#define stepPinY 36//function D36 , port PC1
#define dirPinY 49//function D49 , port PL0
#define Y_MIN_PIN 11//function PWM11, port PB5
#define Y_MAX_PIN -1
#define enPinY 28//function D28 , port PA6
#define Y_MS1_PIN 69//function A15 , port PK7
#define Y_MS2_PIN 39//function D39 , port PG2
//These step pin X2 take place of the Z pinout. The Z pin actually goes from the board to the second x axis motor
#define stepPinX2 35//function D35 , port PC2
#define dirPinX2 47//function D47 , port PL2
#define enPinX2 27//function D27 , port PA5
#define stepPinE0 34//function D34 , port PC3
#define dirPinE0 43//function D43 , port PL6
#define enPinE0 26//function D26 , port PA4
#define E0_MS1_PIN 65//function A11 , port PK3
#define E0_MS2_PIN 66//function D12 , port PK4
#define MOTOR_CURRENT_PWM_XY_PIN 46//function D46 , port PL3
#define MOTOR_CURRENT_PWM_Z_PIN 45//function D45 , port PL4
#define MOTOR_CURRENT_PWM_E_PIN 44//function D44 , port PL5
#define LED_PIN 13//function PWM13, port PB7
//These are as named. These focus on how fast, far, and long the motors move, respectively.
float speedMove = 40; //mm/s
float speedHome = 70; //mm/s
float steps = .15; //mm/step (distance of one step)
int tMove = (steps / (speedMove*2))*1000000;// microsec
int tHome = (steps / (speedHome*2))*1000000;// microsec
//Below we will be defining the buffer size for the probe that will be navigating around the field attached to the end of the positioner. Also
//will be defining the 0,0 point in the x and y plane. CENTER PROBE FOR THIS ITERATION OF CODE!
float buf = 10; //mm
float xloc = 0; //mm
float yloc = 0; //mm
//Setup function initializes all the outputs and inputs of the system
void setup() {
pinMode(stepPinY, OUTPUT); //function D36 , port PC1
pinMode(dirPinY, OUTPUT); //function D49 , port PL0
pinMode(enPinY, OUTPUT); //function D28 , port PA6
pinMode(stepPinX1, OUTPUT); //function D37 , port PD7
pinMode(dirPinX1, OUTPUT); //function D48 , port PL1
pinMode(enPinX1, OUTPUT); //function D29 , port PA7
pinMode(stepPinX2, OUTPUT); //function D35 , port PC2
pinMode(dirPinX2, OUTPUT); //function D47 , port PL2
pinMode(enPinX2, OUTPUT); //function D27 , port PA5
pinMode(stepPinE0, OUTPUT); //function D34 , port PC3
pinMode(dirPinE0, OUTPUT); //function D43 , port PL6
pinMode(enPinE0, OUTPUT); //function D26 , port PA4
//Starts the serial monitor in order to give commands to the motors.
Serial.begin(38400);
}
////Direction functions
//Sets direction of x-axis motors to negative (left)
void moveNegX(){
digitalWrite(dirPinX2,HIGH);
digitalWrite(dirPinX1, LOW);
}
//Sets direction of x-axis motors to positive (right)
void movePosX(){
digitalWrite(dirPinX2,LOW);
digitalWrite(dirPinX1, HIGH);
}
//Sets direction of y-axis motor to negative (left)
void moveNegY(){
digitalWrite(dirPinY, LOW);
}
//Sets direction of y-axis motor to positive (right)
void movePosY(){
digitalWrite(dirPinY, HIGH);
}
//This function will move in the x direction a specified amount (int X) in mm, in the specified direction (int dir)
float moveX(int X, int dir){
if (dir == 2){
movePosX();
}else{
moveNegX();
}
int numxSteps = X/steps;
for (int i = 0; i < numxSteps; i++) {
digitalWrite(stepPinX2,HIGH);
digitalWrite(stepPinX1, HIGH);
delayMicroseconds(tMove);
digitalWrite(stepPinX2,LOW);
digitalWrite(stepPinX1, LOW);
delayMicroseconds(tMove);
}
}
//Same but for y
float moveY(int Y, int dir){
if (dir == 2){
movePosY();
}else{
moveNegY();
}
int numySteps = Y/steps;
for (int i = 0; i < numySteps; i++) {
digitalWrite(stepPinY,HIGH);
delayMicroseconds(tMove);
digitalWrite(stepPinY, LOW);
delayMicroseconds(tMove);
}
}
void loop() {
////TAKE USER INPUT FOR X OR Y////
while (!Serial.available()){
}
int ans = Serial.read();
if (ans == 1 or ans == 2){//move along x- or y-axis
////TAKE USER INPUT FOR NEGATIVE OR POSITIVE////
while (!Serial.available()){
}
int dir = Serial.read();
////TAKE USER INPUT FOR DISTANCE////
while (!Serial.available()){
}
int dist = Serial.read();
delay(500);
if (ans == 1){//move along x-axis
moveX(dist, dir);
}else if (ans == 2){//move along y-axis
moveY(dist, dir);
}
delay(1000);
}
}
And here is my MATLAB code:
s = serialport("COM5",38400);
write(s,2,"uint8")
write(s,2,"uint8")
write(s,10,"uint8")
I tried using Serial.parseInt() instead of Serial.read() in Arduino IDE, but it did not work. I also tried different data types for write(), as well as writeline() in MATLAB, again no luck.
Earlier, I used Serial.print() in Arduino IDE to print to the serial monitor and was able to read it in MATLAB using read(), so I know the connections are good. I appreciate any advice!I am currently building a positioner that will move a probe in the x and y direction through the use of three stepper motors and a RAMBo 1.1b board. I have written code through the Arduino IDE that allows me to do so through inputting options in the serial monitor. My goal is to use MATLAB to build a GUI, and write user inputs from MATLAB to the serial monitor. However, I have not figured out how to write to the serial monitor.
Here is my code that I have uploaded to the board (important code is in the loop):
// These define all the pin outs for the Rambo board
#define ELECTRONICS "RAMBo11b"
#define stepPinX1 37//function D37 , port PD7
#define dirPinX1 48//function D48 , port PL1
#define X_MIN_PIN 12//function PWM12, port PB6
#define X_MAX_PIN 24//function D24 , port PA2
#define enPinX1 29//function D29 , port PA7
#define X_MS1_PIN 40//function D40 , port PG1
#define X_MS2_PIN 41//function D41 , port PG0
#define stepPinY 36//function D36 , port PC1
#define dirPinY 49//function D49 , port PL0
#define Y_MIN_PIN 11//function PWM11, port PB5
#define Y_MAX_PIN -1
#define enPinY 28//function D28 , port PA6
#define Y_MS1_PIN 69//function A15 , port PK7
#define Y_MS2_PIN 39//function D39 , port PG2
//These step pin X2 take place of the Z pinout. The Z pin actually goes from the board to the second x axis motor
#define stepPinX2 35//function D35 , port PC2
#define dirPinX2 47//function D47 , port PL2
#define enPinX2 27//function D27 , port PA5
#define stepPinE0 34//function D34 , port PC3
#define dirPinE0 43//function D43 , port PL6
#define enPinE0 26//function D26 , port PA4
#define E0_MS1_PIN 65//function A11 , port PK3
#define E0_MS2_PIN 66//function D12 , port PK4
#define MOTOR_CURRENT_PWM_XY_PIN 46//function D46 , port PL3
#define MOTOR_CURRENT_PWM_Z_PIN 45//function D45 , port PL4
#define MOTOR_CURRENT_PWM_E_PIN 44//function D44 , port PL5
#define LED_PIN 13//function PWM13, port PB7
//These are as named. These focus on how fast, far, and long the motors move, respectively.
float speedMove = 40; //mm/s
float speedHome = 70; //mm/s
float steps = .15; //mm/step (distance of one step)
int tMove = (steps / (speedMove*2))*1000000;// microsec
int tHome = (steps / (speedHome*2))*1000000;// microsec
//Below we will be defining the buffer size for the probe that will be navigating around the field attached to the end of the positioner. Also
//will be defining the 0,0 point in the x and y plane. CENTER PROBE FOR THIS ITERATION OF CODE!
float buf = 10; //mm
float xloc = 0; //mm
float yloc = 0; //mm
//Setup function initializes all the outputs and inputs of the system
void setup() {
pinMode(stepPinY, OUTPUT); //function D36 , port PC1
pinMode(dirPinY, OUTPUT); //function D49 , port PL0
pinMode(enPinY, OUTPUT); //function D28 , port PA6
pinMode(stepPinX1, OUTPUT); //function D37 , port PD7
pinMode(dirPinX1, OUTPUT); //function D48 , port PL1
pinMode(enPinX1, OUTPUT); //function D29 , port PA7
pinMode(stepPinX2, OUTPUT); //function D35 , port PC2
pinMode(dirPinX2, OUTPUT); //function D47 , port PL2
pinMode(enPinX2, OUTPUT); //function D27 , port PA5
pinMode(stepPinE0, OUTPUT); //function D34 , port PC3
pinMode(dirPinE0, OUTPUT); //function D43 , port PL6
pinMode(enPinE0, OUTPUT); //function D26 , port PA4
//Starts the serial monitor in order to give commands to the motors.
Serial.begin(38400);
}
////Direction functions
//Sets direction of x-axis motors to negative (left)
void moveNegX(){
digitalWrite(dirPinX2,HIGH);
digitalWrite(dirPinX1, LOW);
}
//Sets direction of x-axis motors to positive (right)
void movePosX(){
digitalWrite(dirPinX2,LOW);
digitalWrite(dirPinX1, HIGH);
}
//Sets direction of y-axis motor to negative (left)
void moveNegY(){
digitalWrite(dirPinY, LOW);
}
//Sets direction of y-axis motor to positive (right)
void movePosY(){
digitalWrite(dirPinY, HIGH);
}
//This function will move in the x direction a specified amount (int X) in mm, in the specified direction (int dir)
float moveX(int X, int dir){
if (dir == 2){
movePosX();
}else{
moveNegX();
}
int numxSteps = X/steps;
for (int i = 0; i < numxSteps; i++) {
digitalWrite(stepPinX2,HIGH);
digitalWrite(stepPinX1, HIGH);
delayMicroseconds(tMove);
digitalWrite(stepPinX2,LOW);
digitalWrite(stepPinX1, LOW);
delayMicroseconds(tMove);
}
}
//Same but for y
float moveY(int Y, int dir){
if (dir == 2){
movePosY();
}else{
moveNegY();
}
int numySteps = Y/steps;
for (int i = 0; i < numySteps; i++) {
digitalWrite(stepPinY,HIGH);
delayMicroseconds(tMove);
digitalWrite(stepPinY, LOW);
delayMicroseconds(tMove);
}
}
void loop() {
////TAKE USER INPUT FOR X OR Y////
while (!Serial.available()){
}
int ans = Serial.read();
if (ans == 1 or ans == 2){//move along x- or y-axis
////TAKE USER INPUT FOR NEGATIVE OR POSITIVE////
while (!Serial.available()){
}
int dir = Serial.read();
////TAKE USER INPUT FOR DISTANCE////
while (!Serial.available()){
}
int dist = Serial.read();
delay(500);
if (ans == 1){//move along x-axis
moveX(dist, dir);
}else if (ans == 2){//move along y-axis
moveY(dist, dir);
}
delay(1000);
}
}
And here is my MATLAB code:
s = serialport("COM5",38400);
write(s,2,"uint8")
write(s,2,"uint8")
write(s,10,"uint8")
I tried using Serial.parseInt() instead of Serial.read() in Arduino IDE, but it did not work. I also tried different data types for write(), as well as writeline() in MATLAB, again no luck.
Earlier, I used Serial.print() in Arduino IDE to print to the serial monitor and was able to read it in MATLAB using read(), so I know the connections are good. I appreciate any advice! I am currently building a positioner that will move a probe in the x and y direction through the use of three stepper motors and a RAMBo 1.1b board. I have written code through the Arduino IDE that allows me to do so through inputting options in the serial monitor. My goal is to use MATLAB to build a GUI, and write user inputs from MATLAB to the serial monitor. However, I have not figured out how to write to the serial monitor.
Here is my code that I have uploaded to the board (important code is in the loop):
// These define all the pin outs for the Rambo board
#define ELECTRONICS "RAMBo11b"
#define stepPinX1 37//function D37 , port PD7
#define dirPinX1 48//function D48 , port PL1
#define X_MIN_PIN 12//function PWM12, port PB6
#define X_MAX_PIN 24//function D24 , port PA2
#define enPinX1 29//function D29 , port PA7
#define X_MS1_PIN 40//function D40 , port PG1
#define X_MS2_PIN 41//function D41 , port PG0
#define stepPinY 36//function D36 , port PC1
#define dirPinY 49//function D49 , port PL0
#define Y_MIN_PIN 11//function PWM11, port PB5
#define Y_MAX_PIN -1
#define enPinY 28//function D28 , port PA6
#define Y_MS1_PIN 69//function A15 , port PK7
#define Y_MS2_PIN 39//function D39 , port PG2
//These step pin X2 take place of the Z pinout. The Z pin actually goes from the board to the second x axis motor
#define stepPinX2 35//function D35 , port PC2
#define dirPinX2 47//function D47 , port PL2
#define enPinX2 27//function D27 , port PA5
#define stepPinE0 34//function D34 , port PC3
#define dirPinE0 43//function D43 , port PL6
#define enPinE0 26//function D26 , port PA4
#define E0_MS1_PIN 65//function A11 , port PK3
#define E0_MS2_PIN 66//function D12 , port PK4
#define MOTOR_CURRENT_PWM_XY_PIN 46//function D46 , port PL3
#define MOTOR_CURRENT_PWM_Z_PIN 45//function D45 , port PL4
#define MOTOR_CURRENT_PWM_E_PIN 44//function D44 , port PL5
#define LED_PIN 13//function PWM13, port PB7
//These are as named. These focus on how fast, far, and long the motors move, respectively.
float speedMove = 40; //mm/s
float speedHome = 70; //mm/s
float steps = .15; //mm/step (distance of one step)
int tMove = (steps / (speedMove*2))*1000000;// microsec
int tHome = (steps / (speedHome*2))*1000000;// microsec
//Below we will be defining the buffer size for the probe that will be navigating around the field attached to the end of the positioner. Also
//will be defining the 0,0 point in the x and y plane. CENTER PROBE FOR THIS ITERATION OF CODE!
float buf = 10; //mm
float xloc = 0; //mm
float yloc = 0; //mm
//Setup function initializes all the outputs and inputs of the system
void setup() {
pinMode(stepPinY, OUTPUT); //function D36 , port PC1
pinMode(dirPinY, OUTPUT); //function D49 , port PL0
pinMode(enPinY, OUTPUT); //function D28 , port PA6
pinMode(stepPinX1, OUTPUT); //function D37 , port PD7
pinMode(dirPinX1, OUTPUT); //function D48 , port PL1
pinMode(enPinX1, OUTPUT); //function D29 , port PA7
pinMode(stepPinX2, OUTPUT); //function D35 , port PC2
pinMode(dirPinX2, OUTPUT); //function D47 , port PL2
pinMode(enPinX2, OUTPUT); //function D27 , port PA5
pinMode(stepPinE0, OUTPUT); //function D34 , port PC3
pinMode(dirPinE0, OUTPUT); //function D43 , port PL6
pinMode(enPinE0, OUTPUT); //function D26 , port PA4
//Starts the serial monitor in order to give commands to the motors.
Serial.begin(38400);
}
////Direction functions
//Sets direction of x-axis motors to negative (left)
void moveNegX(){
digitalWrite(dirPinX2,HIGH);
digitalWrite(dirPinX1, LOW);
}
//Sets direction of x-axis motors to positive (right)
void movePosX(){
digitalWrite(dirPinX2,LOW);
digitalWrite(dirPinX1, HIGH);
}
//Sets direction of y-axis motor to negative (left)
void moveNegY(){
digitalWrite(dirPinY, LOW);
}
//Sets direction of y-axis motor to positive (right)
void movePosY(){
digitalWrite(dirPinY, HIGH);
}
//This function will move in the x direction a specified amount (int X) in mm, in the specified direction (int dir)
float moveX(int X, int dir){
if (dir == 2){
movePosX();
}else{
moveNegX();
}
int numxSteps = X/steps;
for (int i = 0; i < numxSteps; i++) {
digitalWrite(stepPinX2,HIGH);
digitalWrite(stepPinX1, HIGH);
delayMicroseconds(tMove);
digitalWrite(stepPinX2,LOW);
digitalWrite(stepPinX1, LOW);
delayMicroseconds(tMove);
}
}
//Same but for y
float moveY(int Y, int dir){
if (dir == 2){
movePosY();
}else{
moveNegY();
}
int numySteps = Y/steps;
for (int i = 0; i < numySteps; i++) {
digitalWrite(stepPinY,HIGH);
delayMicroseconds(tMove);
digitalWrite(stepPinY, LOW);
delayMicroseconds(tMove);
}
}
void loop() {
////TAKE USER INPUT FOR X OR Y////
while (!Serial.available()){
}
int ans = Serial.read();
if (ans == 1 or ans == 2){//move along x- or y-axis
////TAKE USER INPUT FOR NEGATIVE OR POSITIVE////
while (!Serial.available()){
}
int dir = Serial.read();
////TAKE USER INPUT FOR DISTANCE////
while (!Serial.available()){
}
int dist = Serial.read();
delay(500);
if (ans == 1){//move along x-axis
moveX(dist, dir);
}else if (ans == 2){//move along y-axis
moveY(dist, dir);
}
delay(1000);
}
}
And here is my MATLAB code:
s = serialport("COM5",38400);
write(s,2,"uint8")
write(s,2,"uint8")
write(s,10,"uint8")
I tried using Serial.parseInt() instead of Serial.read() in Arduino IDE, but it did not work. I also tried different data types for write(), as well as writeline() in MATLAB, again no luck.
Earlier, I used Serial.print() in Arduino IDE to print to the serial monitor and was able to read it in MATLAB using read(), so I know the connections are good. I appreciate any advice! serial-monitor, arduino-ide, c++, stepper motor, serial-port MATLAB Answers — New Questions
Seeking an Easier Method to Transfer rigidBodyTree Data from MATLAB to SIMULINK
I want to use the rigidBodyTree type data currently in MATLAB in SIMULINK. I’ve heard that the workspaces of the .m file and .slx file are different, so you can’t usually transfer the data using the conventional method.
Some people suggest using the masking function in the Matlab Function Block, while others suggest transferring data using the Matlab System Block.
I’ve been searching and trying to fix this for a week, but both methods were too complicated and difficult for me.
Seeing that the blocks provided in the Manipulator Algorithm of the Robotics System Toolbox recognize the rigidBodyTree type data, it seems necessary to use these two methods, but it’s too difficult for ordinary people to handle these two blocks.
I wonder if there is anyone who can suggest an easier method.
I appreciate your attention.
thank you :)I want to use the rigidBodyTree type data currently in MATLAB in SIMULINK. I’ve heard that the workspaces of the .m file and .slx file are different, so you can’t usually transfer the data using the conventional method.
Some people suggest using the masking function in the Matlab Function Block, while others suggest transferring data using the Matlab System Block.
I’ve been searching and trying to fix this for a week, but both methods were too complicated and difficult for me.
Seeing that the blocks provided in the Manipulator Algorithm of the Robotics System Toolbox recognize the rigidBodyTree type data, it seems necessary to use these two methods, but it’s too difficult for ordinary people to handle these two blocks.
I wonder if there is anyone who can suggest an easier method.
I appreciate your attention.
thank you 🙂 I want to use the rigidBodyTree type data currently in MATLAB in SIMULINK. I’ve heard that the workspaces of the .m file and .slx file are different, so you can’t usually transfer the data using the conventional method.
Some people suggest using the masking function in the Matlab Function Block, while others suggest transferring data using the Matlab System Block.
I’ve been searching and trying to fix this for a week, but both methods were too complicated and difficult for me.
Seeing that the blocks provided in the Manipulator Algorithm of the Robotics System Toolbox recognize the rigidBodyTree type data, it seems necessary to use these two methods, but it’s too difficult for ordinary people to handle these two blocks.
I wonder if there is anyone who can suggest an easier method.
I appreciate your attention.
thank you 🙂 #simulink, #rigidbodytree, #robotarm, #robotics, #robotics system toolbox MATLAB Answers — New Questions
About VR removed in future versions of MAtlab/Simulink and connection with Unreal engine
Hi!
So I saw that in the next versions of Matlab/Simulink, the blocks related to virtual reality (vr sink etc.) will be removed. Now I have built the GUI in the virtual world which then goes with Simulink desktop real time, connected via UDP to a planar robot exchanging data etc.
I have seen that it is recommended for future versions to use Simulink 3d animation with unreal engine, now the problem I am experiencing for example if I use the "Simulation 3 scene configuration" block is that it does not connect to unreal (because of plugins I cannot find, for example "Mathworks interface"). I am using Matlab version 2023b and Unreal engine 5.4.1. Please let me know if anyone has already tried it or can help me thank you very much.
Here in the picture I have attached what my interface looks like in the VR sink block, I wanted to understand how I could translate this with the simulink 3D and unreal engine blocks, thank youHi!
So I saw that in the next versions of Matlab/Simulink, the blocks related to virtual reality (vr sink etc.) will be removed. Now I have built the GUI in the virtual world which then goes with Simulink desktop real time, connected via UDP to a planar robot exchanging data etc.
I have seen that it is recommended for future versions to use Simulink 3d animation with unreal engine, now the problem I am experiencing for example if I use the "Simulation 3 scene configuration" block is that it does not connect to unreal (because of plugins I cannot find, for example "Mathworks interface"). I am using Matlab version 2023b and Unreal engine 5.4.1. Please let me know if anyone has already tried it or can help me thank you very much.
Here in the picture I have attached what my interface looks like in the VR sink block, I wanted to understand how I could translate this with the simulink 3D and unreal engine blocks, thank you Hi!
So I saw that in the next versions of Matlab/Simulink, the blocks related to virtual reality (vr sink etc.) will be removed. Now I have built the GUI in the virtual world which then goes with Simulink desktop real time, connected via UDP to a planar robot exchanging data etc.
I have seen that it is recommended for future versions to use Simulink 3d animation with unreal engine, now the problem I am experiencing for example if I use the "Simulation 3 scene configuration" block is that it does not connect to unreal (because of plugins I cannot find, for example "Mathworks interface"). I am using Matlab version 2023b and Unreal engine 5.4.1. Please let me know if anyone has already tried it or can help me thank you very much.
Here in the picture I have attached what my interface looks like in the VR sink block, I wanted to understand how I could translate this with the simulink 3D and unreal engine blocks, thank you matlab, simulink, unreal engine, vr sink, simulation, test MATLAB Answers — New Questions
Dot indexing is not supported for variables of this type
I am not able to understand why this error occurs. Could any one please correct me here. [Kindly look for underlined line where error occured].
age_ranges = [20 30;31 40;41 50;51 60;61 70]; % Modify as needed
age_labels = {’20-30 years’,’31-40 years’,’41-50 years’,’51-60 years’,’61-70 years’}; % Labels for age ranges
% Create a cell array to store subsets of data based on age ranges
age_groups = cell(size(age_ranges, 1), 1);
% Separate data based on age ranges
for i = 1:size(age_ranges, 1)
% Create logical index for this age range
age_min = age_ranges(i, 1);
age_max = age_ranges(i, 2);
age_idx = data_all_MDV0.AGE >= age_min & data_all_MDV0.AGE <= age_max;
end
% Create subplots for each age group
num_groups = length(age_groups);
figure(3);
for i = 1:num_groups
% Get the subset for this age range
age_data = age_groups{i};
% Number of unique time points
unique_times = unique(age_data.TIME);
% Initialize arrays to store mean and 95th percentile
med_values = zeros(size(unique_times));
percentile_2_5 = zeros(size(unique_times));
percentile_97_5=zeros(size(unique_times));
% Loop over each time point to calculate median and 95th percentile
for j = 1:length(unique_times)
current_time = unique_times(j);
% Get all values for the current time point
current_values = age_data.DV(age_data.TIME == current_time);
% Calculate median
med_values(j) = median(current_values);
% Calculate 2.5th percentile
percentile_2_5(j) = prctile(current_values, 2.5);
% Calculate 97.5th percentile
percentile_97_5(j) = prctile(current_values, 97.5);
endI am not able to understand why this error occurs. Could any one please correct me here. [Kindly look for underlined line where error occured].
age_ranges = [20 30;31 40;41 50;51 60;61 70]; % Modify as needed
age_labels = {’20-30 years’,’31-40 years’,’41-50 years’,’51-60 years’,’61-70 years’}; % Labels for age ranges
% Create a cell array to store subsets of data based on age ranges
age_groups = cell(size(age_ranges, 1), 1);
% Separate data based on age ranges
for i = 1:size(age_ranges, 1)
% Create logical index for this age range
age_min = age_ranges(i, 1);
age_max = age_ranges(i, 2);
age_idx = data_all_MDV0.AGE >= age_min & data_all_MDV0.AGE <= age_max;
end
% Create subplots for each age group
num_groups = length(age_groups);
figure(3);
for i = 1:num_groups
% Get the subset for this age range
age_data = age_groups{i};
% Number of unique time points
unique_times = unique(age_data.TIME);
% Initialize arrays to store mean and 95th percentile
med_values = zeros(size(unique_times));
percentile_2_5 = zeros(size(unique_times));
percentile_97_5=zeros(size(unique_times));
% Loop over each time point to calculate median and 95th percentile
for j = 1:length(unique_times)
current_time = unique_times(j);
% Get all values for the current time point
current_values = age_data.DV(age_data.TIME == current_time);
% Calculate median
med_values(j) = median(current_values);
% Calculate 2.5th percentile
percentile_2_5(j) = prctile(current_values, 2.5);
% Calculate 97.5th percentile
percentile_97_5(j) = prctile(current_values, 97.5);
end I am not able to understand why this error occurs. Could any one please correct me here. [Kindly look for underlined line where error occured].
age_ranges = [20 30;31 40;41 50;51 60;61 70]; % Modify as needed
age_labels = {’20-30 years’,’31-40 years’,’41-50 years’,’51-60 years’,’61-70 years’}; % Labels for age ranges
% Create a cell array to store subsets of data based on age ranges
age_groups = cell(size(age_ranges, 1), 1);
% Separate data based on age ranges
for i = 1:size(age_ranges, 1)
% Create logical index for this age range
age_min = age_ranges(i, 1);
age_max = age_ranges(i, 2);
age_idx = data_all_MDV0.AGE >= age_min & data_all_MDV0.AGE <= age_max;
end
% Create subplots for each age group
num_groups = length(age_groups);
figure(3);
for i = 1:num_groups
% Get the subset for this age range
age_data = age_groups{i};
% Number of unique time points
unique_times = unique(age_data.TIME);
% Initialize arrays to store mean and 95th percentile
med_values = zeros(size(unique_times));
percentile_2_5 = zeros(size(unique_times));
percentile_97_5=zeros(size(unique_times));
% Loop over each time point to calculate median and 95th percentile
for j = 1:length(unique_times)
current_time = unique_times(j);
% Get all values for the current time point
current_values = age_data.DV(age_data.TIME == current_time);
% Calculate median
med_values(j) = median(current_values);
% Calculate 2.5th percentile
percentile_2_5(j) = prctile(current_values, 2.5);
% Calculate 97.5th percentile
percentile_97_5(j) = prctile(current_values, 97.5);
end dot indexing MATLAB Answers — New Questions
Example Px4DemoHostTargetWithSimulinkPlantStart failing during Monitor and Tune
Hello, I have run the example in the name, and the first step of simulation work great, but when I try to perform the second step, Monitor and Tune, where deployment happens it fails saying that it can’t find the flightcontroller.cpp when building the rtw library. I can see that it is trying to use the resulting FlightController.cpp.o but if I look at the artifacts of the project and it is not there. Moment when it fails:
### Creating static library ./FlightController_rtwlib.mk … echo ruvs ./FlightController_rtwlib.mk FlightController.cpp.o process_begin: CreateProcess(NULL, echo ruvs ./FlightController_rtwlib.mk FlightController.cpp.o, …) failed. make (e=2): The system cannot find the file specified.
gmake: *** [FlightController_rtwlib.mk] Error 2 C:UsersuserMATLABProjectsPX4VectorNavIntegrationworkcodeslprjertFlightController>echo The make command returned an error of 2 The make command returned an error of 2
C:UsersuserMATLABProjectsPX4VectorNavIntegrationworkcodeslprjertFlightController>exit 1 ### Build procedure for FlightController aborted due to an error.
Build summary:
Code generation targets built:
Model Action Rebuild Reason ============================================================================
FlightController Failed Code generation information file does not exist.
Top model targets built:
Model Action Rebuild Reason ========================================================================================
px4Demo_FlightController_top Failed Code generation information file does not exist.
0 of 2 models built (0 models already up to date)
Build duration: 0h 0m 14.771s
Any ideas?
Thank you,
JuanHello, I have run the example in the name, and the first step of simulation work great, but when I try to perform the second step, Monitor and Tune, where deployment happens it fails saying that it can’t find the flightcontroller.cpp when building the rtw library. I can see that it is trying to use the resulting FlightController.cpp.o but if I look at the artifacts of the project and it is not there. Moment when it fails:
### Creating static library ./FlightController_rtwlib.mk … echo ruvs ./FlightController_rtwlib.mk FlightController.cpp.o process_begin: CreateProcess(NULL, echo ruvs ./FlightController_rtwlib.mk FlightController.cpp.o, …) failed. make (e=2): The system cannot find the file specified.
gmake: *** [FlightController_rtwlib.mk] Error 2 C:UsersuserMATLABProjectsPX4VectorNavIntegrationworkcodeslprjertFlightController>echo The make command returned an error of 2 The make command returned an error of 2
C:UsersuserMATLABProjectsPX4VectorNavIntegrationworkcodeslprjertFlightController>exit 1 ### Build procedure for FlightController aborted due to an error.
Build summary:
Code generation targets built:
Model Action Rebuild Reason ============================================================================
FlightController Failed Code generation information file does not exist.
Top model targets built:
Model Action Rebuild Reason ========================================================================================
px4Demo_FlightController_top Failed Code generation information file does not exist.
0 of 2 models built (0 models already up to date)
Build duration: 0h 0m 14.771s
Any ideas?
Thank you,
Juan Hello, I have run the example in the name, and the first step of simulation work great, but when I try to perform the second step, Monitor and Tune, where deployment happens it fails saying that it can’t find the flightcontroller.cpp when building the rtw library. I can see that it is trying to use the resulting FlightController.cpp.o but if I look at the artifacts of the project and it is not there. Moment when it fails:
### Creating static library ./FlightController_rtwlib.mk … echo ruvs ./FlightController_rtwlib.mk FlightController.cpp.o process_begin: CreateProcess(NULL, echo ruvs ./FlightController_rtwlib.mk FlightController.cpp.o, …) failed. make (e=2): The system cannot find the file specified.
gmake: *** [FlightController_rtwlib.mk] Error 2 C:UsersuserMATLABProjectsPX4VectorNavIntegrationworkcodeslprjertFlightController>echo The make command returned an error of 2 The make command returned an error of 2
C:UsersuserMATLABProjectsPX4VectorNavIntegrationworkcodeslprjertFlightController>exit 1 ### Build procedure for FlightController aborted due to an error.
Build summary:
Code generation targets built:
Model Action Rebuild Reason ============================================================================
FlightController Failed Code generation information file does not exist.
Top model targets built:
Model Action Rebuild Reason ========================================================================================
px4Demo_FlightController_top Failed Code generation information file does not exist.
0 of 2 models built (0 models already up to date)
Build duration: 0h 0m 14.771s
Any ideas?
Thank you,
Juan px4, uav toolbox MATLAB Answers — New Questions
How to deal with “Transmit unsuccessfully: Could not execute UHD driver command in ‘sendData_c’: tx send error: sequence error”
When I want to send data from USRP X310, it reminds me an error:"Transmit unsuccessfully: Could not execute UHD driver command in ‘sendData_c’: tx send error: sequence error".
I can use USRP to send data, but I can only send around 3M. If it exceeds the limit, the error message will appear.How can I continue to send data? Expect an answer!When I want to send data from USRP X310, it reminds me an error:"Transmit unsuccessfully: Could not execute UHD driver command in ‘sendData_c’: tx send error: sequence error".
I can use USRP to send data, but I can only send around 3M. If it exceeds the limit, the error message will appear.How can I continue to send data? Expect an answer! When I want to send data from USRP X310, it reminds me an error:"Transmit unsuccessfully: Could not execute UHD driver command in ‘sendData_c’: tx send error: sequence error".
I can use USRP to send data, but I can only send around 3M. If it exceeds the limit, the error message will appear.How can I continue to send data? Expect an answer! usrp, error MATLAB Answers — New Questions
i want constant voltage output with varying irradiance in PV Array model, which is not happening in my model. how can i correct it.plz help
i have used boost converter after pv array with output voltage at 300V with 10 KW PV capacityi have used boost converter after pv array with output voltage at 300V with 10 KW PV capacity i have used boost converter after pv array with output voltage at 300V with 10 KW PV capacity pv array boost converter MATLAB Answers — New Questions
Can I nest an if statement in a for loop?
Question as above, supposedly the following code uses an illegal use of a reserved keyword (if), why is this?
for k = [x3,…,xN]
k == 0.5*(x1+x2);
if sign(f(k)) == sign(f(x1))
k = x1;
else
k=x2;
end
endQuestion as above, supposedly the following code uses an illegal use of a reserved keyword (if), why is this?
for k = [x3,…,xN]
k == 0.5*(x1+x2);
if sign(f(k)) == sign(f(x1))
k = x1;
else
k=x2;
end
end Question as above, supposedly the following code uses an illegal use of a reserved keyword (if), why is this?
for k = [x3,…,xN]
k == 0.5*(x1+x2);
if sign(f(k)) == sign(f(x1))
k = x1;
else
k=x2;
end
end if statement, for loop MATLAB Answers — New Questions
Connect Matlab Function Block to Simscape Block (Universal Bridge)
Hello everyone,
I have created a small block for a phase-shifting autotransformer using a Matlab Function Block. However, I cannot connect any of its outputs to a Universal Bridge (Diode) as it belongs to the Simscape Library.
Is it possible to do this? Thanks in advance for your feedback.Hello everyone,
I have created a small block for a phase-shifting autotransformer using a Matlab Function Block. However, I cannot connect any of its outputs to a Universal Bridge (Diode) as it belongs to the Simscape Library.
Is it possible to do this? Thanks in advance for your feedback. Hello everyone,
I have created a small block for a phase-shifting autotransformer using a Matlab Function Block. However, I cannot connect any of its outputs to a Universal Bridge (Diode) as it belongs to the Simscape Library.
Is it possible to do this? Thanks in advance for your feedback. simscape, matlab function, simulink, output, input, diode, universal bridge MATLAB Answers — New Questions
The appearance of infinity in the problem with finding the minimum of a function
I want to find the so-called "efficiency" of a function, defined as the ratio of the difference of the absolute values of the maximum and minimum to their sum. My very simple code is as follows
function z=cur_phi_T_0
x=-2*pi:0.001:2*pi;
r1=1;r2=1;
phi0=1.90132; theta0=1*pi/2;
I1=cos(x/2).*atanh(sin(x/2));
I2=cos((x+2*phi0)/2).*atanh(sin((x+2*phi0)/2));
I3=cos((x+2*theta0)/2).*atanh(sin((x+2*theta0)/2));
I_sum=(I1+r1*I2+r2*I3);
I_min=min(I_sum)
I_max=max(I_sum)
eff=(I_max-abs(I_min))/(I_max+abs(I_min))
plot(x,I_sum,’LineWidth’,3)
grid on
set(gca,’FontName’,’Times New Roman’,’FontSize’,34)
xlabel(‘phi’,’FontName’,’Times New Roman’,’fontsize’,34,’fontweight’,’b’);
ylabel(‘I’,’FontName’,’Times New Roman’,’fontsize’,34,’fontweight’,’b’);
set(gca,’XTick’,-pi:pi/2:pi)
set(gca,’XTickLabel’,{‘-pi’,’-pi/2′,’0′,’pi/2′,’pi’})
end
However, for theta0=pi/2 , I suddenly get infinity for the minimum of the function, even though the plot does not contain infinity.
At the same time for a very close value theta0=0.99999999*pi/2 everything works fine.
What is the reason for this strange behavior?
Update. And how to avoid singularity in calculations?I want to find the so-called "efficiency" of a function, defined as the ratio of the difference of the absolute values of the maximum and minimum to their sum. My very simple code is as follows
function z=cur_phi_T_0
x=-2*pi:0.001:2*pi;
r1=1;r2=1;
phi0=1.90132; theta0=1*pi/2;
I1=cos(x/2).*atanh(sin(x/2));
I2=cos((x+2*phi0)/2).*atanh(sin((x+2*phi0)/2));
I3=cos((x+2*theta0)/2).*atanh(sin((x+2*theta0)/2));
I_sum=(I1+r1*I2+r2*I3);
I_min=min(I_sum)
I_max=max(I_sum)
eff=(I_max-abs(I_min))/(I_max+abs(I_min))
plot(x,I_sum,’LineWidth’,3)
grid on
set(gca,’FontName’,’Times New Roman’,’FontSize’,34)
xlabel(‘phi’,’FontName’,’Times New Roman’,’fontsize’,34,’fontweight’,’b’);
ylabel(‘I’,’FontName’,’Times New Roman’,’fontsize’,34,’fontweight’,’b’);
set(gca,’XTick’,-pi:pi/2:pi)
set(gca,’XTickLabel’,{‘-pi’,’-pi/2′,’0′,’pi/2′,’pi’})
end
However, for theta0=pi/2 , I suddenly get infinity for the minimum of the function, even though the plot does not contain infinity.
At the same time for a very close value theta0=0.99999999*pi/2 everything works fine.
What is the reason for this strange behavior?
Update. And how to avoid singularity in calculations? I want to find the so-called "efficiency" of a function, defined as the ratio of the difference of the absolute values of the maximum and minimum to their sum. My very simple code is as follows
function z=cur_phi_T_0
x=-2*pi:0.001:2*pi;
r1=1;r2=1;
phi0=1.90132; theta0=1*pi/2;
I1=cos(x/2).*atanh(sin(x/2));
I2=cos((x+2*phi0)/2).*atanh(sin((x+2*phi0)/2));
I3=cos((x+2*theta0)/2).*atanh(sin((x+2*theta0)/2));
I_sum=(I1+r1*I2+r2*I3);
I_min=min(I_sum)
I_max=max(I_sum)
eff=(I_max-abs(I_min))/(I_max+abs(I_min))
plot(x,I_sum,’LineWidth’,3)
grid on
set(gca,’FontName’,’Times New Roman’,’FontSize’,34)
xlabel(‘phi’,’FontName’,’Times New Roman’,’fontsize’,34,’fontweight’,’b’);
ylabel(‘I’,’FontName’,’Times New Roman’,’fontsize’,34,’fontweight’,’b’);
set(gca,’XTick’,-pi:pi/2:pi)
set(gca,’XTickLabel’,{‘-pi’,’-pi/2′,’0′,’pi/2′,’pi’})
end
However, for theta0=pi/2 , I suddenly get infinity for the minimum of the function, even though the plot does not contain infinity.
At the same time for a very close value theta0=0.99999999*pi/2 everything works fine.
What is the reason for this strange behavior?
Update. And how to avoid singularity in calculations? plotting, infinity MATLAB Answers — New Questions
How do I extract the multiband data using shape file?
I am using my matlab code to extract the multiband data from envi format using shape file. Code is working without any error but it is not extracting multiband data. I am attaching the code and providing the link for data file and shape file and request you to please have a look on it and suggest me how to extract the multiband data. data link is as follows;
https://drive.google.com/drive/folders/1bnXx0V4V_yfUyWDfKFSxJWlNcWbApuxY?usp=sharingI am using my matlab code to extract the multiband data from envi format using shape file. Code is working without any error but it is not extracting multiband data. I am attaching the code and providing the link for data file and shape file and request you to please have a look on it and suggest me how to extract the multiband data. data link is as follows;
https://drive.google.com/drive/folders/1bnXx0V4V_yfUyWDfKFSxJWlNcWbApuxY?usp=sharing I am using my matlab code to extract the multiband data from envi format using shape file. Code is working without any error but it is not extracting multiband data. I am attaching the code and providing the link for data file and shape file and request you to please have a look on it and suggest me how to extract the multiband data. data link is as follows;
https://drive.google.com/drive/folders/1bnXx0V4V_yfUyWDfKFSxJWlNcWbApuxY?usp=sharing how do i extract the multiband data using shape MATLAB Answers — New Questions
Cannot find this component in Simulink
Does anyone know what is this particular component in Simulink. I have a lab and they ask us to build a circuit using this component but I am struggling to find it.Does anyone know what is this particular component in Simulink. I have a lab and they ask us to build a circuit using this component but I am struggling to find it. Does anyone know what is this particular component in Simulink. I have a lab and they ask us to build a circuit using this component but I am struggling to find it. simulink, clock, component MATLAB Answers — New Questions
Unable to meet integration tolerances without reducing the step size
hello, I tried using ODE45 to solve a system of equations however my graph came out looking wonky as well as a warning of [Warning: Failure at t=3.010481e-15. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (6.310887e-30) at time t.]
clc
clear
%Forward Reaction
k1 = 4.42E+13;
k2 = 6.91E+12;
k3 = 9.74E+14;
k4 = 8.12E+12;
k5 = 5.61E+10;
k6 = 2.40E+16;
k7 = 7.01E+12;
k8 = 3.64E+11;
k9 = 1.53E+12;
k10 = 6.73+16;
k11 = 9.63+16;
k12 = 4.83E+14;
k13 = 2.72E+09;
k14 = 5.38E+04;
k15 = 4.91E+04;
k16 = 1.08E+08;
Kc1 = 5.20E+04;
Kc2 = 1.81E+04;
Kc5 = 6.21E+04;
Kc9 = 8.6E+04;
tspan = [0 10]’;
IC = [10 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5]’;
Pt = 1;
Ct0 = .5;
y = 1;
Ft = 10;
% dFdV = @(V,F) [-k1*(((F(1)/Ft)*Ct0*y)-(((F(2)/Ft) *Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc1)), k1*(((F(1)/Ft)*Ct0*y)-(((F(2)/Ft) *Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc1)),k1*(((F(1)/Ft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ft)+k16*(F(16)*Pt/Ft)^0.31,…
-k15*(F(15)*Pt/Ft),…
-k16*(F(16)*Pt/Ft)^0.31,]’;
[V,F_cal] = ode45(dFdV,tspan,IC);
plot(V,real(F_cal))hello, I tried using ODE45 to solve a system of equations however my graph came out looking wonky as well as a warning of [Warning: Failure at t=3.010481e-15. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (6.310887e-30) at time t.]
clc
clear
%Forward Reaction
k1 = 4.42E+13;
k2 = 6.91E+12;
k3 = 9.74E+14;
k4 = 8.12E+12;
k5 = 5.61E+10;
k6 = 2.40E+16;
k7 = 7.01E+12;
k8 = 3.64E+11;
k9 = 1.53E+12;
k10 = 6.73+16;
k11 = 9.63+16;
k12 = 4.83E+14;
k13 = 2.72E+09;
k14 = 5.38E+04;
k15 = 4.91E+04;
k16 = 1.08E+08;
Kc1 = 5.20E+04;
Kc2 = 1.81E+04;
Kc5 = 6.21E+04;
Kc9 = 8.6E+04;
tspan = [0 10]’;
IC = [10 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5]’;
Pt = 1;
Ct0 = .5;
y = 1;
Ft = 10;
% dFdV = @(V,F) [-k1*(((F(1)/Ft)*Ct0*y)-(((F(2)/Ft) *Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc1)), k1*(((F(1)/Ft)*Ct0*y)-(((F(2)/Ft) *Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc1)),k1*(((F(1)/Ft)*Ct0*y)-(((F(2)/Ft) *Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc1))]’;
% [V,F_cal] = ode45(dFdV,tspan,IC);
% plot(V,F_cal)
dFdV = @(V,F) [-k1*(((F(1)/Ft)*Ct0*y)-(((F(2)/Ft)*Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc1))+k6*((F(9)/Ft)*Ct0*y)*((F(2)/Ft)*Ct0*y)-k8*((F(1)/Ft)*Ct0*y)^2-k10*((F(2)/Ft)*Ct0*y)*((F(1)/Ft)*Ct0*y)-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k2*(((F(4)/Ft)*Ct0*y)-(((F(5)/Ft)*Ct0*y)*((F(6)/Ft)*Ct0*y)/Kc2))+k8*((F(1)/Ft)*Ct0*y)^2+k10*((F(2)/Ft)*Ct0*y)*((F(1)/Ft)*Ct0*y),…
k3*((F(5)/Ft)*Ct0*y)*((F(2)/Ft)*Ct0*y)-k4*((F(2)/Ft)*Ct0*y)*((F(7)/Ft)*Ct0*y)-k14*((F(7)/Ft)*Ct0*y)^1.37,…
k4*((F(2)/Ft)*Ct0*y)*((F(7)/Ft)*Ct0*y),…
-k5*(((F(9)/Ft)*Ct0*y)-(((F(4)/Ft)*Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc5))-k6*((F(9)/Ft)*Ct0*y)*((F(2)/Ft)*Ct0*y)+k8*((F(1)/Ft)*Ct0*y)^2,…
-k9*(((F(10)/Ft)*Ct0*y)-(((F(11)/Ft)*Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc9)),…
k9*(((F(10)/Ft)*Ct0*y)-(((F(11)/Ft)*Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc9))+k11*((F(4)/Ft)*Ct0*y)*((F(1)/Ft)*Ct0*y),…
k12*((F(2)/Ft)*Ct0*y)^1.24+k13*((F(4)/Ft) *Ct0*y)^1.34+k14*((F(7)/Ft)*Ct0*y)^1.37,…
-k15*(F(15)*Pt/Ft)-k16*(F(16)*Pt/Ft)^0.31,…
k15*(F(15)*Pt/Ft)+k16*(F(16)*Pt/Ft)^0.31,…
-k15*(F(15)*Pt/Ft),…
-k16*(F(16)*Pt/Ft)^0.31,]’;
[V,F_cal] = ode45(dFdV,tspan,IC);
plot(V,real(F_cal)) hello, I tried using ODE45 to solve a system of equations however my graph came out looking wonky as well as a warning of [Warning: Failure at t=3.010481e-15. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (6.310887e-30) at time t.]
clc
clear
%Forward Reaction
k1 = 4.42E+13;
k2 = 6.91E+12;
k3 = 9.74E+14;
k4 = 8.12E+12;
k5 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),…
-k5*(((F(9)/Ft)*Ct0*y)-(((F(4)/Ft)*Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc5))-k6*((F(9)/Ft)*Ct0*y)*((F(2)/Ft)*Ct0*y)+k8*((F(1)/Ft)*Ct0*y)^2,…
-k9*(((F(10)/Ft)*Ct0*y)-(((F(11)/Ft)*Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc9)),…
k9*(((F(10)/Ft)*Ct0*y)-(((F(11)/Ft)*Ct0*y)*((F(3)/Ft)*Ct0*y)/Kc9))+k11*((F(4)/Ft)*Ct0*y)*((F(1)/Ft)*Ct0*y),…
k12*((F(2)/Ft)*Ct0*y)^1.24+k13*((F(4)/Ft) *Ct0*y)^1.34+k14*((F(7)/Ft)*Ct0*y)^1.37,…
-k15*(F(15)*Pt/Ft)-k16*(F(16)*Pt/Ft)^0.31,…
k15*(F(15)*Pt/Ft)+k16*(F(16)*Pt/Ft)^0.31,…
-k15*(F(15)*Pt/Ft),…
-k16*(F(16)*Pt/Ft)^0.31,]’;
[V,F_cal] = ode45(dFdV,tspan,IC);
plot(V,real(F_cal)) matlab, ode45, numerical integration, system of odes, kinetics MATLAB Answers — New Questions
Gaussian filter with fspecial versus imgaussfilt
I have two questions. First, I want to filter a function with a Gaussian that has a standard deviation with dimensions of length; units are microns. The dx spacing in the code below has units of microns. If the filters in Matlab require their standard deviation provided in ‘nodes’, is the way to associate the two as such:
x = linspace(-5,5,200); % Units in microns
dx = x(end) – x(end-1); % Spacing in microns
stdev = 0.5; % Desired Gaussian filter standard deviation. Units in microns.
nodesPerSigma = round(stdev/dx,0); % Is this the way to associate nodal sigma with a dimensional sigma?
% Filter with IMGAUSSFILT
zf = imgaussfilt(Z,nodesPerSigma);
My second question is: in the code below, why do zf1 and zf2 produce different results if zf2 matches the result from imgauss filt? The built-in function imgaussfilt selects the filter size based on the sigma provided. It uses 2*ceil(2*sigma)+1 to determine the filter size. This is smaller than the ‘rule of thumb’ (see link below) of 2*3*sigma. Does this mean that imgaussfilt is not using the entire Gaussian??
clear;
x = linspace(-5,5,200); % Units in microns
[X,Y] = meshgrid(x,x);
Z = X .* exp(-X.^2 – Y.^2);
%figure; surf(X,Y,Z)
%figure; plot(X(100,:),Z(100,:))
dx = x(end) – x(end-1); % Spacing in microns
stdev = 0.5; % Desired Gaussian filter standard deviation. Units in microns.
nodesPerSigma = round(stdev/dx,0); % Is this the way to associate nodal sigma with a dimensional sigma?
% Filter with IMGAUSSFILT
zf = imgaussfilt(Z,nodesPerSigma);
filtSize = 2*3*nodesPerSigma;
if mod(filtSize,2) == 0
filtSize = filtSize + 1;
end
% Filter with fspecial’s Gaussian using the ‘rule of thumb’ for the filter
% size. See link below.
gfilter = fspecial(‘gaussian’,[filtSize filtSize],nodesPerSigma);
zf1 = imfilter(Z,gfilter,’same’);
% Filter with fspecial’s Gaussian but using the filter size in documentation.
filtSize2 = 2*ceil(2*nodesPerSigma)+1; % This will produce a result matching the imgaussfilt.
gfilter2 = fspecial(‘gaussian’,[filtSize2 filtSize2],nodesPerSigma);
zf2 = imfilter(Z,gfilter2,’same’);
figure; plot(X(100,:),Z(100,:),’k’,X(100,:),zf(100,:),’r’,X(100,:),zf1(100,:),’g’,X(100,:),zf2(100,:),’*b’)
legend(‘Original Function’,’Using imgaussfilt’,’Using fspecial Gaussian’,’Using fspecial Gaussian Again’)
Link containing info of a rule of thumb for sizing the Gaussian filter. In essence the goal is to include all of the Gaussian curve and not much more, for efficiency.
https://www.mathworks.com/matlabcentral/answers/231351-what-is-the-correct-number-of-pixels-for-a-gaussian-with-a-given-standard-deviation?s_tid=srchtitleI have two questions. First, I want to filter a function with a Gaussian that has a standard deviation with dimensions of length; units are microns. The dx spacing in the code below has units of microns. If the filters in Matlab require their standard deviation provided in ‘nodes’, is the way to associate the two as such:
x = linspace(-5,5,200); % Units in microns
dx = x(end) – x(end-1); % Spacing in microns
stdev = 0.5; % Desired Gaussian filter standard deviation. Units in microns.
nodesPerSigma = round(stdev/dx,0); % Is this the way to associate nodal sigma with a dimensional sigma?
% Filter with IMGAUSSFILT
zf = imgaussfilt(Z,nodesPerSigma);
My second question is: in the code below, why do zf1 and zf2 produce different results if zf2 matches the result from imgauss filt? The built-in function imgaussfilt selects the filter size based on the sigma provided. It uses 2*ceil(2*sigma)+1 to determine the filter size. This is smaller than the ‘rule of thumb’ (see link below) of 2*3*sigma. Does this mean that imgaussfilt is not using the entire Gaussian??
clear;
x = linspace(-5,5,200); % Units in microns
[X,Y] = meshgrid(x,x);
Z = X .* exp(-X.^2 – Y.^2);
%figure; surf(X,Y,Z)
%figure; plot(X(100,:),Z(100,:))
dx = x(end) – x(end-1); % Spacing in microns
stdev = 0.5; % Desired Gaussian filter standard deviation. Units in microns.
nodesPerSigma = round(stdev/dx,0); % Is this the way to associate nodal sigma with a dimensional sigma?
% Filter with IMGAUSSFILT
zf = imgaussfilt(Z,nodesPerSigma);
filtSize = 2*3*nodesPerSigma;
if mod(filtSize,2) == 0
filtSize = filtSize + 1;
end
% Filter with fspecial’s Gaussian using the ‘rule of thumb’ for the filter
% size. See link below.
gfilter = fspecial(‘gaussian’,[filtSize filtSize],nodesPerSigma);
zf1 = imfilter(Z,gfilter,’same’);
% Filter with fspecial’s Gaussian but using the filter size in documentation.
filtSize2 = 2*ceil(2*nodesPerSigma)+1; % This will produce a result matching the imgaussfilt.
gfilter2 = fspecial(‘gaussian’,[filtSize2 filtSize2],nodesPerSigma);
zf2 = imfilter(Z,gfilter2,’same’);
figure; plot(X(100,:),Z(100,:),’k’,X(100,:),zf(100,:),’r’,X(100,:),zf1(100,:),’g’,X(100,:),zf2(100,:),’*b’)
legend(‘Original Function’,’Using imgaussfilt’,’Using fspecial Gaussian’,’Using fspecial Gaussian Again’)
Link containing info of a rule of thumb for sizing the Gaussian filter. In essence the goal is to include all of the Gaussian curve and not much more, for efficiency.
https://www.mathworks.com/matlabcentral/answers/231351-what-is-the-correct-number-of-pixels-for-a-gaussian-with-a-given-standard-deviation?s_tid=srchtitle I have two questions. First, I want to filter a function with a Gaussian that has a standard deviation with dimensions of length; units are microns. The dx spacing in the code below has units of microns. If the filters in Matlab require their standard deviation provided in ‘nodes’, is the way to associate the two as such:
x = linspace(-5,5,200); % Units in microns
dx = x(end) – x(end-1); % Spacing in microns
stdev = 0.5; % Desired Gaussian filter standard deviation. Units in microns.
nodesPerSigma = round(stdev/dx,0); % Is this the way to associate nodal sigma with a dimensional sigma?
% Filter with IMGAUSSFILT
zf = imgaussfilt(Z,nodesPerSigma);
My second question is: in the code below, why do zf1 and zf2 produce different results if zf2 matches the result from imgauss filt? The built-in function imgaussfilt selects the filter size based on the sigma provided. It uses 2*ceil(2*sigma)+1 to determine the filter size. This is smaller than the ‘rule of thumb’ (see link below) of 2*3*sigma. Does this mean that imgaussfilt is not using the entire Gaussian??
clear;
x = linspace(-5,5,200); % Units in microns
[X,Y] = meshgrid(x,x);
Z = X .* exp(-X.^2 – Y.^2);
%figure; surf(X,Y,Z)
%figure; plot(X(100,:),Z(100,:))
dx = x(end) – x(end-1); % Spacing in microns
stdev = 0.5; % Desired Gaussian filter standard deviation. Units in microns.
nodesPerSigma = round(stdev/dx,0); % Is this the way to associate nodal sigma with a dimensional sigma?
% Filter with IMGAUSSFILT
zf = imgaussfilt(Z,nodesPerSigma);
filtSize = 2*3*nodesPerSigma;
if mod(filtSize,2) == 0
filtSize = filtSize + 1;
end
% Filter with fspecial’s Gaussian using the ‘rule of thumb’ for the filter
% size. See link below.
gfilter = fspecial(‘gaussian’,[filtSize filtSize],nodesPerSigma);
zf1 = imfilter(Z,gfilter,’same’);
% Filter with fspecial’s Gaussian but using the filter size in documentation.
filtSize2 = 2*ceil(2*nodesPerSigma)+1; % This will produce a result matching the imgaussfilt.
gfilter2 = fspecial(‘gaussian’,[filtSize2 filtSize2],nodesPerSigma);
zf2 = imfilter(Z,gfilter2,’same’);
figure; plot(X(100,:),Z(100,:),’k’,X(100,:),zf(100,:),’r’,X(100,:),zf1(100,:),’g’,X(100,:),zf2(100,:),’*b’)
legend(‘Original Function’,’Using imgaussfilt’,’Using fspecial Gaussian’,’Using fspecial Gaussian Again’)
Link containing info of a rule of thumb for sizing the Gaussian filter. In essence the goal is to include all of the Gaussian curve and not much more, for efficiency.
https://www.mathworks.com/matlabcentral/answers/231351-what-is-the-correct-number-of-pixels-for-a-gaussian-with-a-given-standard-deviation?s_tid=srchtitle imgaussfilt, fspecial, imfilter, gaussian filter MATLAB Answers — New Questions
Figure Rotation In 3D
Hello,
On executing a certain Matlab code I get a figure displayed (3D)on the screen. I am rotating the figure manually to the desired position. Now, how do I get the position of x,y,z of the rotated figure, so that I can directly use it in the code(using view) and display only the rotated position on the execution of the code instead of rotating it manually each time???
Thanks in advance.Hello,
On executing a certain Matlab code I get a figure displayed (3D)on the screen. I am rotating the figure manually to the desired position. Now, how do I get the position of x,y,z of the rotated figure, so that I can directly use it in the code(using view) and display only the rotated position on the execution of the code instead of rotating it manually each time???
Thanks in advance. Hello,
On executing a certain Matlab code I get a figure displayed (3D)on the screen. I am rotating the figure manually to the desired position. Now, how do I get the position of x,y,z of the rotated figure, so that I can directly use it in the code(using view) and display only the rotated position on the execution of the code instead of rotating it manually each time???
Thanks in advance. rotate, 3d MATLAB Answers — New Questions
Starting pump-controller failed: Not all expected federates logged in in time: missing federates:
This problem occurs when I use Simulink and prescan for CO simulation.After searching for the cause of the problem for many times, it is found that the problem is not caused by prescan. And the corresponding solution can not be found on the Internet. So I hope to get help from mathwork technicians.This problem occurs when I use Simulink and prescan for CO simulation.After searching for the cause of the problem for many times, it is found that the problem is not caused by prescan. And the corresponding solution can not be found on the Internet. So I hope to get help from mathwork technicians. This problem occurs when I use Simulink and prescan for CO simulation.After searching for the cause of the problem for many times, it is found that the problem is not caused by prescan. And the corresponding solution can not be found on the Internet. So I hope to get help from mathwork technicians. prescan, pump-controller MATLAB Answers — New Questions
How to obtain time-averaged wavelet spectral density by the new version of CWT?
I know how to obtain time-averaged wavelet spectral density by the old version of CWT, and the result is similar to the power spectral density (PSD) by function PWELCH. But how to obtain wavelet spectral density by the new version of CWT? Given that the old version is no longger recommended. Thank you. Here is the code and signal I used.
load u.mat
Fs=800; % sampling frequency of signal ‘u’, in Hz;
% PSD by pwelch
SegOvlp=75;
windowL=1024;
window=hamming(windowL);
noverlap=fix(SegOvlp/100*windowL);
nfft=windowL;
[pu_F,f]=pwelch(u,window,noverlap,nfft,Fs);
Pu_F=pu_F*var(u)/trapz(f,pu_F); %normalization
% WSD by old version of CWT, which gives similar results to pwelch
wavename=’gaus3′;
wcf=centfrq(wavename);
fre=10.^(linspace(-0.11,2.6,100));
scal=wcf*Fs./fre;
coefs=cwt(u,scal,wavename);
pu_w=sum(abs(coefs).^2,2)/Fs;
Pu_w=pu_w*var(u)/abs(trapz(fre,pu_w)); %normalization
% figure
loglog(f,Pu_F,’k’);
hold on
loglog(fre,Pu_w,’r’);
xlabel(‘itf/Hz’);ylabel(‘itPSD’);
legend(‘PSD’,’WSD by old CWT’)
set(gcf,’Units’,’centimeters’,’Position’,[10 5 15 8]);
set(gcf,’Color’,’w’);
set(gcf, ‘PaperPositionMode’, ‘auto’);I know how to obtain time-averaged wavelet spectral density by the old version of CWT, and the result is similar to the power spectral density (PSD) by function PWELCH. But how to obtain wavelet spectral density by the new version of CWT? Given that the old version is no longger recommended. Thank you. Here is the code and signal I used.
load u.mat
Fs=800; % sampling frequency of signal ‘u’, in Hz;
% PSD by pwelch
SegOvlp=75;
windowL=1024;
window=hamming(windowL);
noverlap=fix(SegOvlp/100*windowL);
nfft=windowL;
[pu_F,f]=pwelch(u,window,noverlap,nfft,Fs);
Pu_F=pu_F*var(u)/trapz(f,pu_F); %normalization
% WSD by old version of CWT, which gives similar results to pwelch
wavename=’gaus3′;
wcf=centfrq(wavename);
fre=10.^(linspace(-0.11,2.6,100));
scal=wcf*Fs./fre;
coefs=cwt(u,scal,wavename);
pu_w=sum(abs(coefs).^2,2)/Fs;
Pu_w=pu_w*var(u)/abs(trapz(fre,pu_w)); %normalization
% figure
loglog(f,Pu_F,’k’);
hold on
loglog(fre,Pu_w,’r’);
xlabel(‘itf/Hz’);ylabel(‘itPSD’);
legend(‘PSD’,’WSD by old CWT’)
set(gcf,’Units’,’centimeters’,’Position’,[10 5 15 8]);
set(gcf,’Color’,’w’);
set(gcf, ‘PaperPositionMode’, ‘auto’); I know how to obtain time-averaged wavelet spectral density by the old version of CWT, and the result is similar to the power spectral density (PSD) by function PWELCH. But how to obtain wavelet spectral density by the new version of CWT? Given that the old version is no longger recommended. Thank you. Here is the code and signal I used.
load u.mat
Fs=800; % sampling frequency of signal ‘u’, in Hz;
% PSD by pwelch
SegOvlp=75;
windowL=1024;
window=hamming(windowL);
noverlap=fix(SegOvlp/100*windowL);
nfft=windowL;
[pu_F,f]=pwelch(u,window,noverlap,nfft,Fs);
Pu_F=pu_F*var(u)/trapz(f,pu_F); %normalization
% WSD by old version of CWT, which gives similar results to pwelch
wavename=’gaus3′;
wcf=centfrq(wavename);
fre=10.^(linspace(-0.11,2.6,100));
scal=wcf*Fs./fre;
coefs=cwt(u,scal,wavename);
pu_w=sum(abs(coefs).^2,2)/Fs;
Pu_w=pu_w*var(u)/abs(trapz(fre,pu_w)); %normalization
% figure
loglog(f,Pu_F,’k’);
hold on
loglog(fre,Pu_w,’r’);
xlabel(‘itf/Hz’);ylabel(‘itPSD’);
legend(‘PSD’,’WSD by old CWT’)
set(gcf,’Units’,’centimeters’,’Position’,[10 5 15 8]);
set(gcf,’Color’,’w’);
set(gcf, ‘PaperPositionMode’, ‘auto’); cwt, psd MATLAB Answers — New Questions
Booster in LLC resonant converter
Hii, Can anyone help me how to add booster in my LLC resonant converter proposed model? I need to add a booster with the diode rectifier so as to enhance the output voltage. But i have no idea how to do. Can someone give me a direction to place the booster in the system. I have added the pic of my model.Hii, Can anyone help me how to add booster in my LLC resonant converter proposed model? I need to add a booster with the diode rectifier so as to enhance the output voltage. But i have no idea how to do. Can someone give me a direction to place the booster in the system. I have added the pic of my model. Hii, Can anyone help me how to add booster in my LLC resonant converter proposed model? I need to add a booster with the diode rectifier so as to enhance the output voltage. But i have no idea how to do. Can someone give me a direction to place the booster in the system. I have added the pic of my model. llc resonant converter, buck booster, matlab, output voltage MATLAB Answers — New Questions