Tag Archives: matlab
how can i fix this export error in Roadrunner?
1 month ago, I already export this data in RoadRunner.
and today I tried to export same data. but it was not working.
So how can I fix this error?1 month ago, I already export this data in RoadRunner.
and today I tried to export same data. but it was not working.
So how can I fix this error? 1 month ago, I already export this data in RoadRunner.
and today I tried to export same data. but it was not working.
So how can I fix this error? export, roadrunner MATLAB Answers — New Questions
How to highlight a area in figure
I want to hightlight the defect in croppedImage.mat by convHull.mat.
It’s better set transparent.
the size of two figures is same.I want to hightlight the defect in croppedImage.mat by convHull.mat.
It’s better set transparent.
the size of two figures is same. I want to hightlight the defect in croppedImage.mat by convHull.mat.
It’s better set transparent.
the size of two figures is same. highlight area MATLAB Answers — New Questions
Apply ‘rotatefactors’ on the observations to represent them in the new factorial design (PCA)
Hi all,
I guess, that it is an easy issue, but I can not figure out how to apply rotatefactors on the SCORES matrix resulting from a previous PCA:
(1) I run a PCA following:
[wcoeff,score] = pca(zscore(DataSet))
(2) I would like to rotate my principal components using rotatefactors:
[NewCoeff,TransfMatrix] = rotatefactors(wcoeff);
NewCoeff should give the new coordinates of the variables on the varimax-rotated components.
My question is: How can I compute the coordinates ‘NewScores’ of my observations on the new components? My idea is to plot them on a biplot and on an other scatter-plot where each axis is a component.
I guess that there is something easy like:
NewScores = score * TransfMatrix
Am I right?
RomainHi all,
I guess, that it is an easy issue, but I can not figure out how to apply rotatefactors on the SCORES matrix resulting from a previous PCA:
(1) I run a PCA following:
[wcoeff,score] = pca(zscore(DataSet))
(2) I would like to rotate my principal components using rotatefactors:
[NewCoeff,TransfMatrix] = rotatefactors(wcoeff);
NewCoeff should give the new coordinates of the variables on the varimax-rotated components.
My question is: How can I compute the coordinates ‘NewScores’ of my observations on the new components? My idea is to plot them on a biplot and on an other scatter-plot where each axis is a component.
I guess that there is something easy like:
NewScores = score * TransfMatrix
Am I right?
Romain Hi all,
I guess, that it is an easy issue, but I can not figure out how to apply rotatefactors on the SCORES matrix resulting from a previous PCA:
(1) I run a PCA following:
[wcoeff,score] = pca(zscore(DataSet))
(2) I would like to rotate my principal components using rotatefactors:
[NewCoeff,TransfMatrix] = rotatefactors(wcoeff);
NewCoeff should give the new coordinates of the variables on the varimax-rotated components.
My question is: How can I compute the coordinates ‘NewScores’ of my observations on the new components? My idea is to plot them on a biplot and on an other scatter-plot where each axis is a component.
I guess that there is something easy like:
NewScores = score * TransfMatrix
Am I right?
Romain pca, rotatefactors, scores MATLAB Answers — New Questions
Minimize the results in regression model
In my regression model I have four(04) input varibales (Al2O3, TiO2, Pressure, Speed) and there are one responce (Surface roughness(Ra)), So I don’t have idea how find optimum vales for four control factors to minimze the Surface roughness.
To develop this model I have done 16 experiments and the predicted values are shon below
Ra
0.064
0.039
0.071
0.238
3.256
3.910
2.786
0.037
3.604
0.043
0.037
0.060
0.049
0.023
0.061
1.113
Developed Regession Model
Ra = 28.66 + 50.01 Al2O3 + 35.80 TiO2 – 6.925 Pressure – 0.4221 Speed – 182.6 Al2O3*Al2O3 – 3.741 TiO2*TiO2 + 0.7566 Pressure*Pressure + 0.001753 Speed*Speed + 8.210 Al2O3*TiO2 – 2.541 Al2O3*Pressure – 0.04987 Al2O3*Speed – 3.373 TiO2*Pressure – 0.2407 TiO2*Speed + 0.03294 Pressure*Speed + 179.8 Al2O3*Al2O3*Al2O3
Can anyone help me to develop the Maltlab code to solve this problem ? thanks for your valuble time spend on thisIn my regression model I have four(04) input varibales (Al2O3, TiO2, Pressure, Speed) and there are one responce (Surface roughness(Ra)), So I don’t have idea how find optimum vales for four control factors to minimze the Surface roughness.
To develop this model I have done 16 experiments and the predicted values are shon below
Ra
0.064
0.039
0.071
0.238
3.256
3.910
2.786
0.037
3.604
0.043
0.037
0.060
0.049
0.023
0.061
1.113
Developed Regession Model
Ra = 28.66 + 50.01 Al2O3 + 35.80 TiO2 – 6.925 Pressure – 0.4221 Speed – 182.6 Al2O3*Al2O3 – 3.741 TiO2*TiO2 + 0.7566 Pressure*Pressure + 0.001753 Speed*Speed + 8.210 Al2O3*TiO2 – 2.541 Al2O3*Pressure – 0.04987 Al2O3*Speed – 3.373 TiO2*Pressure – 0.2407 TiO2*Speed + 0.03294 Pressure*Speed + 179.8 Al2O3*Al2O3*Al2O3
Can anyone help me to develop the Maltlab code to solve this problem ? thanks for your valuble time spend on this In my regression model I have four(04) input varibales (Al2O3, TiO2, Pressure, Speed) and there are one responce (Surface roughness(Ra)), So I don’t have idea how find optimum vales for four control factors to minimze the Surface roughness.
To develop this model I have done 16 experiments and the predicted values are shon below
Ra
0.064
0.039
0.071
0.238
3.256
3.910
2.786
0.037
3.604
0.043
0.037
0.060
0.049
0.023
0.061
1.113
Developed Regession Model
Ra = 28.66 + 50.01 Al2O3 + 35.80 TiO2 – 6.925 Pressure – 0.4221 Speed – 182.6 Al2O3*Al2O3 – 3.741 TiO2*TiO2 + 0.7566 Pressure*Pressure + 0.001753 Speed*Speed + 8.210 Al2O3*TiO2 – 2.541 Al2O3*Pressure – 0.04987 Al2O3*Speed – 3.373 TiO2*Pressure – 0.2407 TiO2*Speed + 0.03294 Pressure*Speed + 179.8 Al2O3*Al2O3*Al2O3
Can anyone help me to develop the Maltlab code to solve this problem ? thanks for your valuble time spend on this fmincon, optimization MATLAB Answers — New Questions
Single Patch antenna design (not using antenna tool box)
I want to design a single patch antenna (rectangle) and I want to output the beam pattern, S11, as a graph. Is there an expert who can make it S-band resonant frequency 3GHz??
For your information, I can’t use an antenna toolI want to design a single patch antenna (rectangle) and I want to output the beam pattern, S11, as a graph. Is there an expert who can make it S-band resonant frequency 3GHz??
For your information, I can’t use an antenna tool I want to design a single patch antenna (rectangle) and I want to output the beam pattern, S11, as a graph. Is there an expert who can make it S-band resonant frequency 3GHz??
For your information, I can’t use an antenna tool antenna, patch antenna MATLAB Answers — New Questions
Volume of irregular shape
I have for example X,Y,Z coordinates of 8 points which form an irregular shape. How can I calculate the volume with in this shape? Eg. coordinates area:
0 0 384,67
0 26,6 385,25
-47,85 26,6 385,9
-47,85 0 385,3
0 0 387,32
0 26,6 387,32
-47,85 26,6 387,32
-47,85 0 387,32I have for example X,Y,Z coordinates of 8 points which form an irregular shape. How can I calculate the volume with in this shape? Eg. coordinates area:
0 0 384,67
0 26,6 385,25
-47,85 26,6 385,9
-47,85 0 385,3
0 0 387,32
0 26,6 387,32
-47,85 26,6 387,32
-47,85 0 387,32 I have for example X,Y,Z coordinates of 8 points which form an irregular shape. How can I calculate the volume with in this shape? Eg. coordinates area:
0 0 384,67
0 26,6 385,25
-47,85 26,6 385,9
-47,85 0 385,3
0 0 387,32
0 26,6 387,32
-47,85 26,6 387,32
-47,85 0 387,32 voleme, convexhul MATLAB Answers — New Questions
Area of the hysteresis loops
Hi Community,
I have a stress vs. strain plot with approximately 30 different loops, and I need to calculate the area enclosed by each loop. I’ve attached a file containing the stress vs. strain data.
Any help or guidance would be greatly appreciated!
Thank you!Hi Community,
I have a stress vs. strain plot with approximately 30 different loops, and I need to calculate the area enclosed by each loop. I’ve attached a file containing the stress vs. strain data.
Any help or guidance would be greatly appreciated!
Thank you! Hi Community,
I have a stress vs. strain plot with approximately 30 different loops, and I need to calculate the area enclosed by each loop. I’ve attached a file containing the stress vs. strain data.
Any help or guidance would be greatly appreciated!
Thank you! matlab MATLAB Answers — New Questions
Can I implement a reflection wave behavior of a microstrip line in Simulink
Hi,I found a microstrip model in the RF Blockset section, but when I placed it in the circuit and ran the simulation, the oscilloscope did not capture any reflection waves(like ADS). Is it because I didn’t set it up correctly, or is this system just unable to simulate reflection waves?Thanks!Hi,I found a microstrip model in the RF Blockset section, but when I placed it in the circuit and ran the simulation, the oscilloscope did not capture any reflection waves(like ADS). Is it because I didn’t set it up correctly, or is this system just unable to simulate reflection waves?Thanks! Hi,I found a microstrip model in the RF Blockset section, but when I placed it in the circuit and ran the simulation, the oscilloscope did not capture any reflection waves(like ADS). Is it because I didn’t set it up correctly, or is this system just unable to simulate reflection waves?Thanks! microstrip line, reflection MATLAB Answers — New Questions
Even after following MISRA Guidelines and Model adviser ran with zero errors POLYSPACE is throwing MISRA C 2012 violations
Post Content Post Content misra c 2012 violation MATLAB Answers — New Questions
How to remove ‘zeros 0’ from histogram so it will not affect imhistmatchn?
Due to the mask, the histogram contains zeros, which is incorrect. How can I remove the zeros from the histogram, or how can I adjust the histogram function to exclude the zeros? This would ensure that the result will not affect the result of the imhistmatch function.
Thank you.Due to the mask, the histogram contains zeros, which is incorrect. How can I remove the zeros from the histogram, or how can I adjust the histogram function to exclude the zeros? This would ensure that the result will not affect the result of the imhistmatch function.
Thank you. Due to the mask, the histogram contains zeros, which is incorrect. How can I remove the zeros from the histogram, or how can I adjust the histogram function to exclude the zeros? This would ensure that the result will not affect the result of the imhistmatch function.
Thank you. histogram, imhistmatchn, matlab, zeros MATLAB Answers — New Questions
Why parameterized MOSFETs does not show response
Hey,
I have an EV model where velocity is controlled via PMSM FOC blockset and when using ideal converter, the model is correctly following the reference speed and generating torque as expected and even when I put MOSFET (Ideal Switching), the model response is as expected, however, when I parameterized the same MOSFETs using preparameterized MOSFET or even I do the parameterizaton on my own using N-Channel MOSFET using datasheet, the response is 0.
I have done the tuning via trial and error and even tried to change the gains to see even some response.
I am attaching the Model here, any expert in this modelling can have look and guide on the issue.Hey,
I have an EV model where velocity is controlled via PMSM FOC blockset and when using ideal converter, the model is correctly following the reference speed and generating torque as expected and even when I put MOSFET (Ideal Switching), the model response is as expected, however, when I parameterized the same MOSFETs using preparameterized MOSFET or even I do the parameterizaton on my own using N-Channel MOSFET using datasheet, the response is 0.
I have done the tuning via trial and error and even tried to change the gains to see even some response.
I am attaching the Model here, any expert in this modelling can have look and guide on the issue. Hey,
I have an EV model where velocity is controlled via PMSM FOC blockset and when using ideal converter, the model is correctly following the reference speed and generating torque as expected and even when I put MOSFET (Ideal Switching), the model response is as expected, however, when I parameterized the same MOSFETs using preparameterized MOSFET or even I do the parameterizaton on my own using N-Channel MOSFET using datasheet, the response is 0.
I have done the tuning via trial and error and even tried to change the gains to see even some response.
I am attaching the Model here, any expert in this modelling can have look and guide on the issue. simscape, power_electronics_control MATLAB Answers — New Questions
Ideas on generalizing the syntax used for constructing complex variables
I am looking for ideas on how to construct a class that generalizes the interface Matlab uses for creating and manipulating complex variables. The general idea is that one could construct a "pets" object by simplying typing:
mypets = 2dogs + 3cats
which would create an object of the pets class.
I can think of a few clunky ways to do this, such as having the constructor parse a string like this:
mypets = pets(‘2dogs + 3cats’).
Another slightly nicer way would be to leave out the parenthesis like this:
pets 2dogs + 3cats
but this still requires an explicit constructor reference. Any ideas anyone?I am looking for ideas on how to construct a class that generalizes the interface Matlab uses for creating and manipulating complex variables. The general idea is that one could construct a "pets" object by simplying typing:
mypets = 2dogs + 3cats
which would create an object of the pets class.
I can think of a few clunky ways to do this, such as having the constructor parse a string like this:
mypets = pets(‘2dogs + 3cats’).
Another slightly nicer way would be to leave out the parenthesis like this:
pets 2dogs + 3cats
but this still requires an explicit constructor reference. Any ideas anyone? I am looking for ideas on how to construct a class that generalizes the interface Matlab uses for creating and manipulating complex variables. The general idea is that one could construct a "pets" object by simplying typing:
mypets = 2dogs + 3cats
which would create an object of the pets class.
I can think of a few clunky ways to do this, such as having the constructor parse a string like this:
mypets = pets(‘2dogs + 3cats’).
Another slightly nicer way would be to leave out the parenthesis like this:
pets 2dogs + 3cats
but this still requires an explicit constructor reference. Any ideas anyone? generalize complex MATLAB Answers — New Questions
Satellite basemap attribution block too large
I am trying to use readBasemapImage to read satellite imagery. However, the image I get has an enormous attribution block, most of which appears to be empty space instead of attribution. Is there a way to read the basemap so that block is an appropriate size, without increasing the zoom level (for better performance panning around the image)? For some reason, if I use "Run with R2024a" in the question editor, it works fine, but doesn’t on my personal computer or laptop (image attached)?
[img, rast, attrib] = readBasemapImage("satellite", [38.7 39.1], [-77.5 -76.9], 14);
mapshow(img, rast);I am trying to use readBasemapImage to read satellite imagery. However, the image I get has an enormous attribution block, most of which appears to be empty space instead of attribution. Is there a way to read the basemap so that block is an appropriate size, without increasing the zoom level (for better performance panning around the image)? For some reason, if I use "Run with R2024a" in the question editor, it works fine, but doesn’t on my personal computer or laptop (image attached)?
[img, rast, attrib] = readBasemapImage("satellite", [38.7 39.1], [-77.5 -76.9], 14);
mapshow(img, rast); I am trying to use readBasemapImage to read satellite imagery. However, the image I get has an enormous attribution block, most of which appears to be empty space instead of attribution. Is there a way to read the basemap so that block is an appropriate size, without increasing the zoom level (for better performance panning around the image)? For some reason, if I use "Run with R2024a" in the question editor, it works fine, but doesn’t on my personal computer or laptop (image attached)?
[img, rast, attrib] = readBasemapImage("satellite", [38.7 39.1], [-77.5 -76.9], 14);
mapshow(img, rast); image MATLAB Answers — New Questions
Figures saved with MATLAB New Desktop cannot be opened in MATLAB Online or on the local computer with MATLAB Old Desktop
Hello,
I have some figures that I saved in MATLAB R2024b with New Desktop on my work computer. When I try to open the figure on my home computer using MATLAB R2024b with Old Desktop, it freezes at FigureController.m at the sendACT function. The exact same thing happens with MATLAB Online too. It freezes at the exact same point. However, if I switch to New Desktop on my local computer, I can see the figures again. The figures are not big at all, they are 100kB maximum.
Is there a solution to this?Hello,
I have some figures that I saved in MATLAB R2024b with New Desktop on my work computer. When I try to open the figure on my home computer using MATLAB R2024b with Old Desktop, it freezes at FigureController.m at the sendACT function. The exact same thing happens with MATLAB Online too. It freezes at the exact same point. However, if I switch to New Desktop on my local computer, I can see the figures again. The figures are not big at all, they are 100kB maximum.
Is there a solution to this? Hello,
I have some figures that I saved in MATLAB R2024b with New Desktop on my work computer. When I try to open the figure on my home computer using MATLAB R2024b with Old Desktop, it freezes at FigureController.m at the sendACT function. The exact same thing happens with MATLAB Online too. It freezes at the exact same point. However, if I switch to New Desktop on my local computer, I can see the figures again. The figures are not big at all, they are 100kB maximum.
Is there a solution to this? matlab, figure, matlab gui MATLAB Answers — New Questions
Custom loss function (based on error multiplication rather than sum) in classification neural network
Hi everyone,
First, thank you! This is a fantastic community from which I’m learning so much. This is my first question (hopefully, I’ll be able to contribute answers in the future!).
I have a system consisting of 10 elements, where each element can exist in one of four states (or classes). This means the system has 410410 possible states. For each element, I have 61 features that can be used to predict its state. I’ve experimented with different neural networks (FF networks have worked well so far), mainly focusing on predicting the labels of individual elements.
However, I’ve encountered some challenges:
The classes are naturally imbalanced.
The problem is non-deterministic, meaning two identical feature vectors can correspond to different labels.
I’ve been addressing these issues with relative success by applying techniques such as downsampling, oversampling, data augmentation, and soft labels (the latter has been the most effective).
Now, I want to predict the probability of the entire system being in each of its 410410 states. One issue I’ve noticed is that a misclassification error of 0.05 has minimal impact when the classification is close to random (e.g., 0.25), but it has a significant impact when probabilities are closer to 1 or 0.
What I’d like to do next is implement a loss function that considers the entire system rather than individual elements, while still being based on predictions for each element. My idea is to:
Take batches of 10 observations (corresponding to the 10 elements of the system).
Compute the probability of each element belonging to each of the 4 classes.
Calculate the probability of the system being in each of its 410410 possible states based on these predictions.
Sort these probabilities and use the known labels to find the index of the correct state.
Minimize this index.
Does this approach make sense? Is it feasible? And if so, how could it be implemented?
Many thanks!
DavidHi everyone,
First, thank you! This is a fantastic community from which I’m learning so much. This is my first question (hopefully, I’ll be able to contribute answers in the future!).
I have a system consisting of 10 elements, where each element can exist in one of four states (or classes). This means the system has 410410 possible states. For each element, I have 61 features that can be used to predict its state. I’ve experimented with different neural networks (FF networks have worked well so far), mainly focusing on predicting the labels of individual elements.
However, I’ve encountered some challenges:
The classes are naturally imbalanced.
The problem is non-deterministic, meaning two identical feature vectors can correspond to different labels.
I’ve been addressing these issues with relative success by applying techniques such as downsampling, oversampling, data augmentation, and soft labels (the latter has been the most effective).
Now, I want to predict the probability of the entire system being in each of its 410410 states. One issue I’ve noticed is that a misclassification error of 0.05 has minimal impact when the classification is close to random (e.g., 0.25), but it has a significant impact when probabilities are closer to 1 or 0.
What I’d like to do next is implement a loss function that considers the entire system rather than individual elements, while still being based on predictions for each element. My idea is to:
Take batches of 10 observations (corresponding to the 10 elements of the system).
Compute the probability of each element belonging to each of the 4 classes.
Calculate the probability of the system being in each of its 410410 possible states based on these predictions.
Sort these probabilities and use the known labels to find the index of the correct state.
Minimize this index.
Does this approach make sense? Is it feasible? And if so, how could it be implemented?
Many thanks!
David Hi everyone,
First, thank you! This is a fantastic community from which I’m learning so much. This is my first question (hopefully, I’ll be able to contribute answers in the future!).
I have a system consisting of 10 elements, where each element can exist in one of four states (or classes). This means the system has 410410 possible states. For each element, I have 61 features that can be used to predict its state. I’ve experimented with different neural networks (FF networks have worked well so far), mainly focusing on predicting the labels of individual elements.
However, I’ve encountered some challenges:
The classes are naturally imbalanced.
The problem is non-deterministic, meaning two identical feature vectors can correspond to different labels.
I’ve been addressing these issues with relative success by applying techniques such as downsampling, oversampling, data augmentation, and soft labels (the latter has been the most effective).
Now, I want to predict the probability of the entire system being in each of its 410410 states. One issue I’ve noticed is that a misclassification error of 0.05 has minimal impact when the classification is close to random (e.g., 0.25), but it has a significant impact when probabilities are closer to 1 or 0.
What I’d like to do next is implement a loss function that considers the entire system rather than individual elements, while still being based on predictions for each element. My idea is to:
Take batches of 10 observations (corresponding to the 10 elements of the system).
Compute the probability of each element belonging to each of the 4 classes.
Calculate the probability of the system being in each of its 410410 possible states based on these predictions.
Sort these probabilities and use the known labels to find the index of the correct state.
Minimize this index.
Does this approach make sense? Is it feasible? And if so, how could it be implemented?
Many thanks!
David neural network, classification, loss function, fast forward, trainnet MATLAB Answers — New Questions
What is the best practice for creating a recursion loop?
Hello all! I am trying to create a simple program that creates a fractal. It is supposed to be putting complex values into an array from the initial conditions and I will plot them later.
My Questions are:
1. What is the correct way to implement an Anonymous Function?
2. What is the best practice in Matlab for a recursion loop?
The answer to question 1 may not be necessary if the answer to 2 does not use Anonymous Functions.
clear all
clc
F = @(z) z^2 + c;
Re = [];
Im = [];
x = 1;
y = 1;
a = 2;
b = 3;
n = 10;
c = x+y*1i;
z0 = a+b*1i;
% Placing values in arrays to be plotted
Re(1,1) = real(z0 + c);
Im(1,1) = imag(z0 + c);
F(z0) = z; % First step of the recursion outside for loop?
% Second values for the array
Re(2,1) = real(z);
Im(2,1) = imag(z);
for h = (3:n) % Begin recursion
F(z) = z;
Re(h,1) = real(z);
Im(h,1) = imag(z);
h = h + 1;
endHello all! I am trying to create a simple program that creates a fractal. It is supposed to be putting complex values into an array from the initial conditions and I will plot them later.
My Questions are:
1. What is the correct way to implement an Anonymous Function?
2. What is the best practice in Matlab for a recursion loop?
The answer to question 1 may not be necessary if the answer to 2 does not use Anonymous Functions.
clear all
clc
F = @(z) z^2 + c;
Re = [];
Im = [];
x = 1;
y = 1;
a = 2;
b = 3;
n = 10;
c = x+y*1i;
z0 = a+b*1i;
% Placing values in arrays to be plotted
Re(1,1) = real(z0 + c);
Im(1,1) = imag(z0 + c);
F(z0) = z; % First step of the recursion outside for loop?
% Second values for the array
Re(2,1) = real(z);
Im(2,1) = imag(z);
for h = (3:n) % Begin recursion
F(z) = z;
Re(h,1) = real(z);
Im(h,1) = imag(z);
h = h + 1;
end Hello all! I am trying to create a simple program that creates a fractal. It is supposed to be putting complex values into an array from the initial conditions and I will plot them later.
My Questions are:
1. What is the correct way to implement an Anonymous Function?
2. What is the best practice in Matlab for a recursion loop?
The answer to question 1 may not be necessary if the answer to 2 does not use Anonymous Functions.
clear all
clc
F = @(z) z^2 + c;
Re = [];
Im = [];
x = 1;
y = 1;
a = 2;
b = 3;
n = 10;
c = x+y*1i;
z0 = a+b*1i;
% Placing values in arrays to be plotted
Re(1,1) = real(z0 + c);
Im(1,1) = imag(z0 + c);
F(z0) = z; % First step of the recursion outside for loop?
% Second values for the array
Re(2,1) = real(z);
Im(2,1) = imag(z);
for h = (3:n) % Begin recursion
F(z) = z;
Re(h,1) = real(z);
Im(h,1) = imag(z);
h = h + 1;
end anonymous function, recursion, fractal MATLAB Answers — New Questions
ROS Logger doesn’t show the topics
I am working with MATLAB R2024b on a Simulink model. I want to publish some topics using ROS2. I added some topics in different place of the model, one of them is at depth 1 from the main system and the rest are at depth 5-6 from the main system (as shown in the 2 images). When I use ROS Logger to create a ROS bag, it only show the one topic at depth 1. I have chosen "Log Selected Signal" to all of the Topic. I am not sure if subsytem depth is the reason, but I need to create a log file for all topics. There is a same discussion, but no solution is shown there.
Depth 1 topic:
Depth 5 topic:
Can you suggest the solution?I am working with MATLAB R2024b on a Simulink model. I want to publish some topics using ROS2. I added some topics in different place of the model, one of them is at depth 1 from the main system and the rest are at depth 5-6 from the main system (as shown in the 2 images). When I use ROS Logger to create a ROS bag, it only show the one topic at depth 1. I have chosen "Log Selected Signal" to all of the Topic. I am not sure if subsytem depth is the reason, but I need to create a log file for all topics. There is a same discussion, but no solution is shown there.
Depth 1 topic:
Depth 5 topic:
Can you suggest the solution? I am working with MATLAB R2024b on a Simulink model. I want to publish some topics using ROS2. I added some topics in different place of the model, one of them is at depth 1 from the main system and the rest are at depth 5-6 from the main system (as shown in the 2 images). When I use ROS Logger to create a ROS bag, it only show the one topic at depth 1. I have chosen "Log Selected Signal" to all of the Topic. I am not sure if subsytem depth is the reason, but I need to create a log file for all topics. There is a same discussion, but no solution is shown there.
Depth 1 topic:
Depth 5 topic:
Can you suggest the solution? ros2, simulink, ros-logger MATLAB Answers — New Questions
Error on Symbolic calculation : “Empty sym : 0-by-1”
I need the help of people who have excellent talents in calculating using Matlab.
The equations to be implemented through Matlab coding is as follows.
The results to be obtained through this coding is written in "Answer) ~" above.
And, the data related to this problem(or eqution) is below.
I have tried with the following coding but kept getting the same results as the title. I would like to get helpful advice on this part.
I would appreciate it if you could give me a guide on the solution or error cause.
v1 = [393 393 393 393 393 393 393 393 393 393 ; 3850 4340 4760 5320 5740 6160 6580 7140 7980 8960];
v2 = [408 408 408 408 408 408 408 408 408 408 ; 3300 3720 4080 4560 4920 5280 5640 6120 6840 7680];
v3 = [423 423 423 423 423 423 423 423 423 423 ; 2750 3100 3400 3800 4100 4400 4700 5100 5700 6400];
syms B; % parameter Beta
syms BB; % parameter B
syms C;
%————- equation 1 ————-%
a1_v1 = 0;
a1_v2 = 0;
a1_v3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
a1_v1 = N*log(v1(i+1,j)/C/exp(BB/v1(i,j))) + a1_v1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
a1_v2 = N*log(v2(i+1,j)/C/exp(BB/v2(i,j))) + a1_v2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
a1_v3 = N*log(v3(i+1,j)/C/exp(BB/v3(i,j))) + a1_v3;
end
a2_v1 = 0;
a2_v2 = 0;
a2_v3 = 0;
i = 1; % "Stress Lv. 1" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
a2_v1 = N*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B*log(v1(i+1,j)/C/exp(BB/v1(i,j))) + a2_v1;
end
i = 1; % "Stress Lv. 2" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
a2_v2 = N*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B*log(v2(i+1,j)/C/exp(BB/v2(i,j))) + a2_v2;
end
i = 1; % "Stress Lv. 3" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
a2_v3 = N*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B*log(v3(i+1,j)/C/exp(BB/v3(i,j))) + a2_v3;
end
a1 = a1_v1 + a1_v2 + a1_v3;
a2 = a2_v1 + a2_v2 + a2_v3;
N = numel(v1(1,:)) + numel(v2(1,:))+ numel(v3(1,:)); % the first term of ∂Λ/∂β(equation 1)
one = N/B + a1 – a2;
%————- equation 2 ————-%
b1_v1 = 0;
b1_v2 = 0;
b1_v3 = 0;
i = 1; % "Stress Lv. 1" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
b1_v1 = N/v1(i,j) + b1_v1;
end
i = 1; % "Stress Lv. 2" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
b1_v2 = N/v2(i,j) + b1_v2;
end
i = 1; % "Stress Lv. 3" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
b1_v3 = N/v3(i,j) + b1_v3;
end
b2_v1 = 0;
b2_v2 = 0;
b2_v3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
b2_v1 = N/v1(i,j)*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B+b2_v1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
b2_v2 = N/v2(i,j)*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B+b2_v2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
b2_v3 = N/v3(i,j)*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B+b2_v3;
end
b1 = b1_v1 + b1_v2 + b1_v3;
b2 = b2_v1 + b2_v2 + b2_v3;
two = B*(- b1 + b2);
%————- equation 3 ————-%
c1 = 0;
c2 = 0;
c3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
c1 = N*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B+c1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
c2 = N*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B+c2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
c3 = N*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B+c3;
end
N = numel(v1(1,:)) + numel(v2(1,:)) + numel(v3(1,:)); % the first term of ∂Λ/∂C(equation 3)
three = B/C*(- N + (c1 + c2 + c3));
eqns = [one == 0, two == 0, three == 0];
vars = [B BB C];
answer = solve(eqns, vars);
vpa(answer.B)
vpa(answer.BB)
vpa(answer.C)I need the help of people who have excellent talents in calculating using Matlab.
The equations to be implemented through Matlab coding is as follows.
The results to be obtained through this coding is written in "Answer) ~" above.
And, the data related to this problem(or eqution) is below.
I have tried with the following coding but kept getting the same results as the title. I would like to get helpful advice on this part.
I would appreciate it if you could give me a guide on the solution or error cause.
v1 = [393 393 393 393 393 393 393 393 393 393 ; 3850 4340 4760 5320 5740 6160 6580 7140 7980 8960];
v2 = [408 408 408 408 408 408 408 408 408 408 ; 3300 3720 4080 4560 4920 5280 5640 6120 6840 7680];
v3 = [423 423 423 423 423 423 423 423 423 423 ; 2750 3100 3400 3800 4100 4400 4700 5100 5700 6400];
syms B; % parameter Beta
syms BB; % parameter B
syms C;
%————- equation 1 ————-%
a1_v1 = 0;
a1_v2 = 0;
a1_v3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
a1_v1 = N*log(v1(i+1,j)/C/exp(BB/v1(i,j))) + a1_v1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
a1_v2 = N*log(v2(i+1,j)/C/exp(BB/v2(i,j))) + a1_v2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
a1_v3 = N*log(v3(i+1,j)/C/exp(BB/v3(i,j))) + a1_v3;
end
a2_v1 = 0;
a2_v2 = 0;
a2_v3 = 0;
i = 1; % "Stress Lv. 1" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
a2_v1 = N*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B*log(v1(i+1,j)/C/exp(BB/v1(i,j))) + a2_v1;
end
i = 1; % "Stress Lv. 2" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
a2_v2 = N*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B*log(v2(i+1,j)/C/exp(BB/v2(i,j))) + a2_v2;
end
i = 1; % "Stress Lv. 3" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
a2_v3 = N*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B*log(v3(i+1,j)/C/exp(BB/v3(i,j))) + a2_v3;
end
a1 = a1_v1 + a1_v2 + a1_v3;
a2 = a2_v1 + a2_v2 + a2_v3;
N = numel(v1(1,:)) + numel(v2(1,:))+ numel(v3(1,:)); % the first term of ∂Λ/∂β(equation 1)
one = N/B + a1 – a2;
%————- equation 2 ————-%
b1_v1 = 0;
b1_v2 = 0;
b1_v3 = 0;
i = 1; % "Stress Lv. 1" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
b1_v1 = N/v1(i,j) + b1_v1;
end
i = 1; % "Stress Lv. 2" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
b1_v2 = N/v2(i,j) + b1_v2;
end
i = 1; % "Stress Lv. 3" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
b1_v3 = N/v3(i,j) + b1_v3;
end
b2_v1 = 0;
b2_v2 = 0;
b2_v3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
b2_v1 = N/v1(i,j)*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B+b2_v1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
b2_v2 = N/v2(i,j)*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B+b2_v2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
b2_v3 = N/v3(i,j)*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B+b2_v3;
end
b1 = b1_v1 + b1_v2 + b1_v3;
b2 = b2_v1 + b2_v2 + b2_v3;
two = B*(- b1 + b2);
%————- equation 3 ————-%
c1 = 0;
c2 = 0;
c3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
c1 = N*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B+c1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
c2 = N*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B+c2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
c3 = N*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B+c3;
end
N = numel(v1(1,:)) + numel(v2(1,:)) + numel(v3(1,:)); % the first term of ∂Λ/∂C(equation 3)
three = B/C*(- N + (c1 + c2 + c3));
eqns = [one == 0, two == 0, three == 0];
vars = [B BB C];
answer = solve(eqns, vars);
vpa(answer.B)
vpa(answer.BB)
vpa(answer.C) I need the help of people who have excellent talents in calculating using Matlab.
The equations to be implemented through Matlab coding is as follows.
The results to be obtained through this coding is written in "Answer) ~" above.
And, the data related to this problem(or eqution) is below.
I have tried with the following coding but kept getting the same results as the title. I would like to get helpful advice on this part.
I would appreciate it if you could give me a guide on the solution or error cause.
v1 = [393 393 393 393 393 393 393 393 393 393 ; 3850 4340 4760 5320 5740 6160 6580 7140 7980 8960];
v2 = [408 408 408 408 408 408 408 408 408 408 ; 3300 3720 4080 4560 4920 5280 5640 6120 6840 7680];
v3 = [423 423 423 423 423 423 423 423 423 423 ; 2750 3100 3400 3800 4100 4400 4700 5100 5700 6400];
syms B; % parameter Beta
syms BB; % parameter B
syms C;
%————- equation 1 ————-%
a1_v1 = 0;
a1_v2 = 0;
a1_v3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
a1_v1 = N*log(v1(i+1,j)/C/exp(BB/v1(i,j))) + a1_v1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
a1_v2 = N*log(v2(i+1,j)/C/exp(BB/v2(i,j))) + a1_v2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
a1_v3 = N*log(v3(i+1,j)/C/exp(BB/v3(i,j))) + a1_v3;
end
a2_v1 = 0;
a2_v2 = 0;
a2_v3 = 0;
i = 1; % "Stress Lv. 1" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
a2_v1 = N*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B*log(v1(i+1,j)/C/exp(BB/v1(i,j))) + a2_v1;
end
i = 1; % "Stress Lv. 2" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
a2_v2 = N*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B*log(v2(i+1,j)/C/exp(BB/v2(i,j))) + a2_v2;
end
i = 1; % "Stress Lv. 3" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
a2_v3 = N*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B*log(v3(i+1,j)/C/exp(BB/v3(i,j))) + a2_v3;
end
a1 = a1_v1 + a1_v2 + a1_v3;
a2 = a2_v1 + a2_v2 + a2_v3;
N = numel(v1(1,:)) + numel(v2(1,:))+ numel(v3(1,:)); % the first term of ∂Λ/∂β(equation 1)
one = N/B + a1 – a2;
%————- equation 2 ————-%
b1_v1 = 0;
b1_v2 = 0;
b1_v3 = 0;
i = 1; % "Stress Lv. 1" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
b1_v1 = N/v1(i,j) + b1_v1;
end
i = 1; % "Stress Lv. 2" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
b1_v2 = N/v2(i,j) + b1_v2;
end
i = 1; % "Stress Lv. 3" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
b1_v3 = N/v3(i,j) + b1_v3;
end
b2_v1 = 0;
b2_v2 = 0;
b2_v3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
b2_v1 = N/v1(i,j)*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B+b2_v1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
b2_v2 = N/v2(i,j)*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B+b2_v2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
b2_v3 = N/v3(i,j)*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B+b2_v3;
end
b1 = b1_v1 + b1_v2 + b1_v3;
b2 = b2_v1 + b2_v2 + b2_v3;
two = B*(- b1 + b2);
%————- equation 3 ————-%
c1 = 0;
c2 = 0;
c3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
c1 = N*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B+c1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
c2 = N*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B+c2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
c3 = N*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B+c3;
end
N = numel(v1(1,:)) + numel(v2(1,:)) + numel(v3(1,:)); % the first term of ∂Λ/∂C(equation 3)
three = B/C*(- N + (c1 + c2 + c3));
eqns = [one == 0, two == 0, three == 0];
vars = [B BB C];
answer = solve(eqns, vars);
vpa(answer.B)
vpa(answer.BB)
vpa(answer.C) vpa, equation, 0-by-1, threeparameteres, solve, stresslevel MATLAB Answers — New Questions
Different answers each run halving step size, debugging code correctly
Hello,
I have a code computing a rockets trajectory using Rungekutta. The issue is computing error, I am trying to compute and estimated global error, by comparing two results with different step size. There is a while loop in the code, which halves the step size to compute local truncation error and minimize this. However, I descided to deactivate this, so the issue is not here. I have tried to search trough the code various times, but I can not seem to find an issue anywhere.
Any help is greatly appriciatedHello,
I have a code computing a rockets trajectory using Rungekutta. The issue is computing error, I am trying to compute and estimated global error, by comparing two results with different step size. There is a while loop in the code, which halves the step size to compute local truncation error and minimize this. However, I descided to deactivate this, so the issue is not here. I have tried to search trough the code various times, but I can not seem to find an issue anywhere.
Any help is greatly appriciated Hello,
I have a code computing a rockets trajectory using Rungekutta. The issue is computing error, I am trying to compute and estimated global error, by comparing two results with different step size. There is a while loop in the code, which halves the step size to compute local truncation error and minimize this. However, I descided to deactivate this, so the issue is not here. I have tried to search trough the code various times, but I can not seem to find an issue anywhere.
Any help is greatly appriciated runge-kutta, ode, rocket trajectory MATLAB Answers — New Questions
Detecting a serial port valid after disconnect/reconnect
I asked before with a long question and got no answers, so let’s keep it simpler.
Serial port is connected to Arduino
Arduino resets, so I need to:
1. Detect that it’s gone without throwing an error
2. Reconnect
Results:
Connected and callback set
K>> app.Pico
ans =
Serialport with properties:
Port: "COM16"
BaudRate: 57600
NumBytesAvailable: 0
Hit reset on Pico get following error message ( but it doesn’t stop my program from running)
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
If there is no "keep alive" function for serial ports ( Walter Roberson in https://www.mathworks.com/matlabcentral/answers/1722140-cant-read-the-serial-port) then what is generating this error? How can I catch it without constantly checking the connection myself?
If I could trap the error here that would be a great start.
So let’s look at where we are:
K>> app.PicoCom
ans =
Serialport with properties:
In ‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter {0}.
Not useful, but I can check it right?
K>> isvalid(app.PicoCom)
ans =
logical
1
Really? It’s still valid? Let’s try
K>> serialportlist("available")
ans =
1×2 string array
"COM1" "COM16"
OK, at least I can see it’s back in the list of available ports. Is this the best (fastest) way to find out?
Also I can’t check in the input call back because then it’s too late. Error thrown already.
K>> delete(app.PicoCom)
K>> app.PicoCom
ans =
handle to deleted Serialport
K>> isvalid(app.PicoCom)
ans =
logical
0
At least once deleted it’s not valid. Let’s reconnect:
K>> app.PicoCom = serialport()
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM16"
BaudRate: 57600
NumBytesAvailable: 0
ByteOrder: "little-endian"
DataBits: 8
StopBits: 1
Parity: "none"
FlowControl: "none"
Timeout: 10
Terminator: "CR/LF"
Back to normal as soon as I add
K>> configureCallback(app.PicoCom,"terminator",@app.PicoInput);
So I think I’ve got recovery OK. How about detecting when coms are lost?
BTW serialportfind is only useful when teh prot is there. If it’s missing then looking throws an error…
K>> serialportfind
ans =
Serialport with properties:
In ‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter {0}.
Apparently it’s a valid question to ask, just not a useful answer.
K>> isvalid(serialportfind)’
ans =
logical
1I asked before with a long question and got no answers, so let’s keep it simpler.
Serial port is connected to Arduino
Arduino resets, so I need to:
1. Detect that it’s gone without throwing an error
2. Reconnect
Results:
Connected and callback set
K>> app.Pico
ans =
Serialport with properties:
Port: "COM16"
BaudRate: 57600
NumBytesAvailable: 0
Hit reset on Pico get following error message ( but it doesn’t stop my program from running)
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
If there is no "keep alive" function for serial ports ( Walter Roberson in https://www.mathworks.com/matlabcentral/answers/1722140-cant-read-the-serial-port) then what is generating this error? How can I catch it without constantly checking the connection myself?
If I could trap the error here that would be a great start.
So let’s look at where we are:
K>> app.PicoCom
ans =
Serialport with properties:
In ‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter {0}.
Not useful, but I can check it right?
K>> isvalid(app.PicoCom)
ans =
logical
1
Really? It’s still valid? Let’s try
K>> serialportlist("available")
ans =
1×2 string array
"COM1" "COM16"
OK, at least I can see it’s back in the list of available ports. Is this the best (fastest) way to find out?
Also I can’t check in the input call back because then it’s too late. Error thrown already.
K>> delete(app.PicoCom)
K>> app.PicoCom
ans =
handle to deleted Serialport
K>> isvalid(app.PicoCom)
ans =
logical
0
At least once deleted it’s not valid. Let’s reconnect:
K>> app.PicoCom = serialport()
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM16"
BaudRate: 57600
NumBytesAvailable: 0
ByteOrder: "little-endian"
DataBits: 8
StopBits: 1
Parity: "none"
FlowControl: "none"
Timeout: 10
Terminator: "CR/LF"
Back to normal as soon as I add
K>> configureCallback(app.PicoCom,"terminator",@app.PicoInput);
So I think I’ve got recovery OK. How about detecting when coms are lost?
BTW serialportfind is only useful when teh prot is there. If it’s missing then looking throws an error…
K>> serialportfind
ans =
Serialport with properties:
In ‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter {0}.
Apparently it’s a valid question to ask, just not a useful answer.
K>> isvalid(serialportfind)’
ans =
logical
1 I asked before with a long question and got no answers, so let’s keep it simpler.
Serial port is connected to Arduino
Arduino resets, so I need to:
1. Detect that it’s gone without throwing an error
2. Reconnect
Results:
Connected and callback set
K>> app.Pico
ans =
Serialport with properties:
Port: "COM16"
BaudRate: 57600
NumBytesAvailable: 0
Hit reset on Pico get following error message ( but it doesn’t stop my program from running)
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
If there is no "keep alive" function for serial ports ( Walter Roberson in https://www.mathworks.com/matlabcentral/answers/1722140-cant-read-the-serial-port) then what is generating this error? How can I catch it without constantly checking the connection myself?
If I could trap the error here that would be a great start.
So let’s look at where we are:
K>> app.PicoCom
ans =
Serialport with properties:
In ‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter {0}.
Not useful, but I can check it right?
K>> isvalid(app.PicoCom)
ans =
logical
1
Really? It’s still valid? Let’s try
K>> serialportlist("available")
ans =
1×2 string array
"COM1" "COM16"
OK, at least I can see it’s back in the list of available ports. Is this the best (fastest) way to find out?
Also I can’t check in the input call back because then it’s too late. Error thrown already.
K>> delete(app.PicoCom)
K>> app.PicoCom
ans =
handle to deleted Serialport
K>> isvalid(app.PicoCom)
ans =
logical
0
At least once deleted it’s not valid. Let’s reconnect:
K>> app.PicoCom = serialport()
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM16"
BaudRate: 57600
NumBytesAvailable: 0
ByteOrder: "little-endian"
DataBits: 8
StopBits: 1
Parity: "none"
FlowControl: "none"
Timeout: 10
Terminator: "CR/LF"
Back to normal as soon as I add
K>> configureCallback(app.PicoCom,"terminator",@app.PicoInput);
So I think I’ve got recovery OK. How about detecting when coms are lost?
BTW serialportfind is only useful when teh prot is there. If it’s missing then looking throws an error…
K>> serialportfind
ans =
Serialport with properties:
In ‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter {0}.
Apparently it’s a valid question to ask, just not a useful answer.
K>> isvalid(serialportfind)’
ans =
logical
1 serial, usb, reconnect MATLAB Answers — New Questions