Category: Matlab
Category Archives: Matlab
Mask R-CNN maximum number of detected instances per image.
Hi, I’ve been working on the mask r-cnn following the documentation instructions. I’ve got everything tot work but I stumbled upon a potential library mistake. Let me explain better my situation: I am working on a dataset with ~250 images (split between training and validation) and with just 1 category. Each image might have 40-50 instances up to 600-650 instances.
The problem is this, mask r-cnn can only detect up to 100 instances by class definition. I believe this is hurting the training of the network – however I cannot confirm this because I have to run the training by remote, by command prompt, since I don’t have a GPU powerful enough to run the training locally. My evidence is that the network, after the training, performs somewhat well on images with 40-50 instances, while it performs horrible on images with a lot of instances. In fact, when I evaluate my network on the validation set (something that I can do on my own computer), the network outputs at most 100 masks per image.
My "local" fix: I edited the maskrcnn.m file of the library. I went to the directory "C:ProgramFilesMATLABR2023btoolboxvisionvision@maskrcnnmaskrcnn.m" and at line 172 of the code, instead of
NumStrongestRegionsPrediction = 100
I put (expecting to not detect more than 800 instances, given my ground truth data)
NumStrongestRegionsPrediction = 800
which fixes my issue at least at validation time. However, since my training is run without this fix and, given my results, I am writing here to ask what I can do about this issue, I am basically certain my code is correct.
Again, all I can observe at training time is the training loss, which converges to a good number, however sometimes it outputs a bigger number, probably because it encounters the batch with the images with a lot of instances – in other words, the network isn’t learning enough out of these images and mistakes/training loss.
I can provide more information if needed, however for now I want to keep the post simple.Hi, I’ve been working on the mask r-cnn following the documentation instructions. I’ve got everything tot work but I stumbled upon a potential library mistake. Let me explain better my situation: I am working on a dataset with ~250 images (split between training and validation) and with just 1 category. Each image might have 40-50 instances up to 600-650 instances.
The problem is this, mask r-cnn can only detect up to 100 instances by class definition. I believe this is hurting the training of the network – however I cannot confirm this because I have to run the training by remote, by command prompt, since I don’t have a GPU powerful enough to run the training locally. My evidence is that the network, after the training, performs somewhat well on images with 40-50 instances, while it performs horrible on images with a lot of instances. In fact, when I evaluate my network on the validation set (something that I can do on my own computer), the network outputs at most 100 masks per image.
My "local" fix: I edited the maskrcnn.m file of the library. I went to the directory "C:ProgramFilesMATLABR2023btoolboxvisionvision@maskrcnnmaskrcnn.m" and at line 172 of the code, instead of
NumStrongestRegionsPrediction = 100
I put (expecting to not detect more than 800 instances, given my ground truth data)
NumStrongestRegionsPrediction = 800
which fixes my issue at least at validation time. However, since my training is run without this fix and, given my results, I am writing here to ask what I can do about this issue, I am basically certain my code is correct.
Again, all I can observe at training time is the training loss, which converges to a good number, however sometimes it outputs a bigger number, probably because it encounters the batch with the images with a lot of instances – in other words, the network isn’t learning enough out of these images and mistakes/training loss.
I can provide more information if needed, however for now I want to keep the post simple. Hi, I’ve been working on the mask r-cnn following the documentation instructions. I’ve got everything tot work but I stumbled upon a potential library mistake. Let me explain better my situation: I am working on a dataset with ~250 images (split between training and validation) and with just 1 category. Each image might have 40-50 instances up to 600-650 instances.
The problem is this, mask r-cnn can only detect up to 100 instances by class definition. I believe this is hurting the training of the network – however I cannot confirm this because I have to run the training by remote, by command prompt, since I don’t have a GPU powerful enough to run the training locally. My evidence is that the network, after the training, performs somewhat well on images with 40-50 instances, while it performs horrible on images with a lot of instances. In fact, when I evaluate my network on the validation set (something that I can do on my own computer), the network outputs at most 100 masks per image.
My "local" fix: I edited the maskrcnn.m file of the library. I went to the directory "C:ProgramFilesMATLABR2023btoolboxvisionvision@maskrcnnmaskrcnn.m" and at line 172 of the code, instead of
NumStrongestRegionsPrediction = 100
I put (expecting to not detect more than 800 instances, given my ground truth data)
NumStrongestRegionsPrediction = 800
which fixes my issue at least at validation time. However, since my training is run without this fix and, given my results, I am writing here to ask what I can do about this issue, I am basically certain my code is correct.
Again, all I can observe at training time is the training loss, which converges to a good number, however sometimes it outputs a bigger number, probably because it encounters the batch with the images with a lot of instances – in other words, the network isn’t learning enough out of these images and mistakes/training loss.
I can provide more information if needed, however for now I want to keep the post simple. deep learning, image segmentation, cnn MATLAB Answers — New Questions
Read and Display Dicom files from a folder as 3d
Hi all,
I was wondering how to read and display dicom files from a folder as a 3d image. The dicom slices are from a CT dataset. Any suggestions ?Hi all,
I was wondering how to read and display dicom files from a folder as a 3d image. The dicom slices are from a CT dataset. Any suggestions ? Hi all,
I was wondering how to read and display dicom files from a folder as a 3d image. The dicom slices are from a CT dataset. Any suggestions ? dicom, viewer, mat file, 3d MATLAB Answers — New Questions
changing dataset in SORT (simple online real-time tracking) example in Matlab
Hello. I want to use my dataset as input to the SORT example ( https://www.mathworks.com/help/fusion/ug/implement-simple-online-and-realtime-tracking.html ) in Matlab. I used the yolo4 object detection algorithm and set the input for the SORT algorithm. I attached my input data to the SORT example, which is in objectDetection format as it should be. when I run the SORT algorithm with my dataset, this error happens:
error using ()
changing the data type on input 3 of the system object trackerGNN is not allowed without first calling the release(.) method.
Error in helperRunSort (line 18)
tracks = tracker(highScoreDetections, reader.CurrentTime, iouCost);
I would appreciate it if anyone could help me solve this issue. Regards
whos -file objectDetectionsCell.matHello. I want to use my dataset as input to the SORT example ( https://www.mathworks.com/help/fusion/ug/implement-simple-online-and-realtime-tracking.html ) in Matlab. I used the yolo4 object detection algorithm and set the input for the SORT algorithm. I attached my input data to the SORT example, which is in objectDetection format as it should be. when I run the SORT algorithm with my dataset, this error happens:
error using ()
changing the data type on input 3 of the system object trackerGNN is not allowed without first calling the release(.) method.
Error in helperRunSort (line 18)
tracks = tracker(highScoreDetections, reader.CurrentTime, iouCost);
I would appreciate it if anyone could help me solve this issue. Regards
whos -file objectDetectionsCell.mat Hello. I want to use my dataset as input to the SORT example ( https://www.mathworks.com/help/fusion/ug/implement-simple-online-and-realtime-tracking.html ) in Matlab. I used the yolo4 object detection algorithm and set the input for the SORT algorithm. I attached my input data to the SORT example, which is in objectDetection format as it should be. when I run the SORT algorithm with my dataset, this error happens:
error using ()
changing the data type on input 3 of the system object trackerGNN is not allowed without first calling the release(.) method.
Error in helperRunSort (line 18)
tracks = tracker(highScoreDetections, reader.CurrentTime, iouCost);
I would appreciate it if anyone could help me solve this issue. Regards
whos -file objectDetectionsCell.mat object tracking, sort, simple online ral time tracking, error in matlab example MATLAB Answers — New Questions
How to calculate real roots of a polynomial equation under square root ?
syms t
coupler_parametric=[5163136522924301/2251799813685248,…
2^(1/2)/2 – (8*t)/(t^2 + 1), – (4*(t^2 – 1))/(t^2 + 1) – 2];
norm(coupler_parametric)
%upto this step ,i have calculated norm, if t can be any real number
%further i want to calculate real roots of equation given below,
eq= norm(coupler_parametric)-3.5;
%please help someone
%thanks!!syms t
coupler_parametric=[5163136522924301/2251799813685248,…
2^(1/2)/2 – (8*t)/(t^2 + 1), – (4*(t^2 – 1))/(t^2 + 1) – 2];
norm(coupler_parametric)
%upto this step ,i have calculated norm, if t can be any real number
%further i want to calculate real roots of equation given below,
eq= norm(coupler_parametric)-3.5;
%please help someone
%thanks!! syms t
coupler_parametric=[5163136522924301/2251799813685248,…
2^(1/2)/2 – (8*t)/(t^2 + 1), – (4*(t^2 – 1))/(t^2 + 1) – 2];
norm(coupler_parametric)
%upto this step ,i have calculated norm, if t can be any real number
%further i want to calculate real roots of equation given below,
eq= norm(coupler_parametric)-3.5;
%please help someone
%thanks!! #roots, #polynomial MATLAB Answers — New Questions
Stop simulation block effect on aborting generated code execution.
Hello,
I have a SIMULINK model that contains a STOP SIMULATION block which is activated for a certian condition. When I generated the C code for this model by embedded coder and did a SIL, I noticed that the condition was not called in the execution and the code kept running until the simulation time even the condition was true.
The question is: is STOP SIMULATION block affect in the generated code ? I mean that is it generated like interrupt or something that stops the execution and return to the main function? Or it is just useful in the MIL ?Hello,
I have a SIMULINK model that contains a STOP SIMULATION block which is activated for a certian condition. When I generated the C code for this model by embedded coder and did a SIL, I noticed that the condition was not called in the execution and the code kept running until the simulation time even the condition was true.
The question is: is STOP SIMULATION block affect in the generated code ? I mean that is it generated like interrupt or something that stops the execution and return to the main function? Or it is just useful in the MIL ? Hello,
I have a SIMULINK model that contains a STOP SIMULATION block which is activated for a certian condition. When I generated the C code for this model by embedded coder and did a SIL, I noticed that the condition was not called in the execution and the code kept running until the simulation time even the condition was true.
The question is: is STOP SIMULATION block affect in the generated code ? I mean that is it generated like interrupt or something that stops the execution and return to the main function? Or it is just useful in the MIL ? simulink, matlab, embedded coder MATLAB Answers — New Questions
is it built in function or a structure ?
This is from the matalb documentation of reconfigurable intelligent surfaces. helperRISSurface is function or a structure ? how can i pass parameters?
i tried to rum this and i am getting error here. i have uploaded the screenshots
kindly help me
thank you.
=========================================================================
ris = helperRISSurface(‘Size’,[Nr Nc],’ElementSpacing’,[dr dc],…
‘ReflectorElement’,phased.IsotropicAntennaElement,’OperatingFrequency’,fc)
ris =
helperRISSurface with properties:
ReflectorElement: [1×1 phased.IsotropicAntennaElement]
Size: [10 20]
ElementSpacing: [0.0054 0.0054]
OperatingFrequency: 2.8000e+10
=====================================================================This is from the matalb documentation of reconfigurable intelligent surfaces. helperRISSurface is function or a structure ? how can i pass parameters?
i tried to rum this and i am getting error here. i have uploaded the screenshots
kindly help me
thank you.
=========================================================================
ris = helperRISSurface(‘Size’,[Nr Nc],’ElementSpacing’,[dr dc],…
‘ReflectorElement’,phased.IsotropicAntennaElement,’OperatingFrequency’,fc)
ris =
helperRISSurface with properties:
ReflectorElement: [1×1 phased.IsotropicAntennaElement]
Size: [10 20]
ElementSpacing: [0.0054 0.0054]
OperatingFrequency: 2.8000e+10
===================================================================== This is from the matalb documentation of reconfigurable intelligent surfaces. helperRISSurface is function or a structure ? how can i pass parameters?
i tried to rum this and i am getting error here. i have uploaded the screenshots
kindly help me
thank you.
=========================================================================
ris = helperRISSurface(‘Size’,[Nr Nc],’ElementSpacing’,[dr dc],…
‘ReflectorElement’,phased.IsotropicAntennaElement,’OperatingFrequency’,fc)
ris =
helperRISSurface with properties:
ReflectorElement: [1×1 phased.IsotropicAntennaElement]
Size: [10 20]
ElementSpacing: [0.0054 0.0054]
OperatingFrequency: 2.8000e+10
===================================================================== coding in matlab MATLAB Answers — New Questions
objectDetection (Report for single object detection) and YOLO.
Hello everyone!
I need some help with using the Object Detection function in YOLO to obtain detection results based on frames. I’ve tried various codes, but the results are not what I expect. Any advice or guidance would be greatly appreciated.
for example
Video = VideoReader("tr.avi",CurrentTime=0);
player = vision.VideoPlayer;
detections = {};
measurementNoise = 10;
while hasFrame(Video)
frame = readFrame(Video);
frameIndex = round(Video.CurrentTime * Video.FrameRate);
[bbox, score, label] = detect(detector, frame);
if length(detections) < frameIndex
detections{frameIndex} = {};
end
for i = 1:length(score)
detections{frameIndex}{end+1} = objectDetection(frameIndex, bbox(i,:), …
"MeasurementNoise", measurementNoise, "ObjectAttributes", struct("Score", score(i)));
end
Object = insertObjectAnnotation(frame, "rectangle", bbox, label, "Color", "green");
step(player, Object);
end
Thank you!Hello everyone!
I need some help with using the Object Detection function in YOLO to obtain detection results based on frames. I’ve tried various codes, but the results are not what I expect. Any advice or guidance would be greatly appreciated.
for example
Video = VideoReader("tr.avi",CurrentTime=0);
player = vision.VideoPlayer;
detections = {};
measurementNoise = 10;
while hasFrame(Video)
frame = readFrame(Video);
frameIndex = round(Video.CurrentTime * Video.FrameRate);
[bbox, score, label] = detect(detector, frame);
if length(detections) < frameIndex
detections{frameIndex} = {};
end
for i = 1:length(score)
detections{frameIndex}{end+1} = objectDetection(frameIndex, bbox(i,:), …
"MeasurementNoise", measurementNoise, "ObjectAttributes", struct("Score", score(i)));
end
Object = insertObjectAnnotation(frame, "rectangle", bbox, label, "Color", "green");
step(player, Object);
end
Thank you! Hello everyone!
I need some help with using the Object Detection function in YOLO to obtain detection results based on frames. I’ve tried various codes, but the results are not what I expect. Any advice or guidance would be greatly appreciated.
for example
Video = VideoReader("tr.avi",CurrentTime=0);
player = vision.VideoPlayer;
detections = {};
measurementNoise = 10;
while hasFrame(Video)
frame = readFrame(Video);
frameIndex = round(Video.CurrentTime * Video.FrameRate);
[bbox, score, label] = detect(detector, frame);
if length(detections) < frameIndex
detections{frameIndex} = {};
end
for i = 1:length(score)
detections{frameIndex}{end+1} = objectDetection(frameIndex, bbox(i,:), …
"MeasurementNoise", measurementNoise, "ObjectAttributes", struct("Score", score(i)));
end
Object = insertObjectAnnotation(frame, "rectangle", bbox, label, "Color", "green");
step(player, Object);
end
Thank you! objectdetection MATLAB Answers — New Questions
missing “configure for app” in matlab 2019b app designer
Hi,
I want to creat custom component for matlab app designer .
I cannot find the "configure for app" button?
in addition, I also cannot run it from the commend line:
>> appdesigner.customcomponent.configureMetadata(‘C:funcsBandC1_exported.m’);
Unable to resolve the name appdesigner.customcomponent.configureMetadata.
how to creat it?Hi,
I want to creat custom component for matlab app designer .
I cannot find the "configure for app" button?
in addition, I also cannot run it from the commend line:
>> appdesigner.customcomponent.configureMetadata(‘C:funcsBandC1_exported.m’);
Unable to resolve the name appdesigner.customcomponent.configureMetadata.
how to creat it? Hi,
I want to creat custom component for matlab app designer .
I cannot find the "configure for app" button?
in addition, I also cannot run it from the commend line:
>> appdesigner.customcomponent.configureMetadata(‘C:funcsBandC1_exported.m’);
Unable to resolve the name appdesigner.customcomponent.configureMetadata.
how to creat it? configure, custom component, appdesigner MATLAB Answers — New Questions
How to find norm of a 3 X 1 matrix if it contains components in parametric form?
%i have this coupler matrix in parametric form
syms t
coupler_parametric=[5163136522924301/2251799813685248, 2^(1/2)/2 – (8*t)/(t^2 + 1), – (4*(t^2 – 1))/(t^2 + 1) – 2];
i want to find magnitude of this matrix in terms of t
please someone help%i have this coupler matrix in parametric form
syms t
coupler_parametric=[5163136522924301/2251799813685248, 2^(1/2)/2 – (8*t)/(t^2 + 1), – (4*(t^2 – 1))/(t^2 + 1) – 2];
i want to find magnitude of this matrix in terms of t
please someone help %i have this coupler matrix in parametric form
syms t
coupler_parametric=[5163136522924301/2251799813685248, 2^(1/2)/2 – (8*t)/(t^2 + 1), – (4*(t^2 – 1))/(t^2 + 1) – 2];
i want to find magnitude of this matrix in terms of t
please someone help #symbolic, #matrix MATLAB Answers — New Questions
Driving Open manipulator through Dynamics in Simulink
this is my simulink model for driving my open manipulator 4 DOF robot Dynamics
waypoints
wp = [
0.35 0.25 0.25 0.15 0.15 0.25;
0 0.01 0.11 0.11 0.01 0.01;
0.11 0.11 0.11 0.11 0.11 0.11 ];
error
Error:Error in port widths or dimensions. ‘Output Port 1’ of ‘untitled1/Trapezoidal Velocity Profile Trajectory’ is a [3×1] matrix.
Error:Error in port widths or dimensions. ‘Input Port 1’ of ‘untitled1/Forward Dynamics’ is a one dimensional vector with 6 elements.this is my simulink model for driving my open manipulator 4 DOF robot Dynamics
waypoints
wp = [
0.35 0.25 0.25 0.15 0.15 0.25;
0 0.01 0.11 0.11 0.01 0.01;
0.11 0.11 0.11 0.11 0.11 0.11 ];
error
Error:Error in port widths or dimensions. ‘Output Port 1’ of ‘untitled1/Trapezoidal Velocity Profile Trajectory’ is a [3×1] matrix.
Error:Error in port widths or dimensions. ‘Input Port 1’ of ‘untitled1/Forward Dynamics’ is a one dimensional vector with 6 elements. this is my simulink model for driving my open manipulator 4 DOF robot Dynamics
waypoints
wp = [
0.35 0.25 0.25 0.15 0.15 0.25;
0 0.01 0.11 0.11 0.01 0.01;
0.11 0.11 0.11 0.11 0.11 0.11 ];
error
Error:Error in port widths or dimensions. ‘Output Port 1’ of ‘untitled1/Trapezoidal Velocity Profile Trajectory’ is a [3×1] matrix.
Error:Error in port widths or dimensions. ‘Input Port 1’ of ‘untitled1/Forward Dynamics’ is a one dimensional vector with 6 elements. open manipulator, simulink MATLAB Answers — New Questions
Format output from jsonencode to make it more human readable
Can someone provide an example to format the output from jsonencode to make it more human readable. I.E. add carriage returns and indentations.Can someone provide an example to format the output from jsonencode to make it more human readable. I.E. add carriage returns and indentations. Can someone provide an example to format the output from jsonencode to make it more human readable. I.E. add carriage returns and indentations. jsonencode MATLAB Answers — New Questions
Issues with Quadcopter Deep Reinforcement Learning Training in Simulink
Hi guys,
I’ve been experimenting with training a quadcopter using Simulink in MATLAB for deep reinforcement learning. My objective is to train it to navigate from one hovering point to another point in space. However, I’ve encountered significant challenges, and the results have been far from satisfactory.
Could anyone provide suggestions or insights into potential issues that might be causing this? thank youHi guys,
I’ve been experimenting with training a quadcopter using Simulink in MATLAB for deep reinforcement learning. My objective is to train it to navigate from one hovering point to another point in space. However, I’ve encountered significant challenges, and the results have been far from satisfactory.
Could anyone provide suggestions or insights into potential issues that might be causing this? thank you Hi guys,
I’ve been experimenting with training a quadcopter using Simulink in MATLAB for deep reinforcement learning. My objective is to train it to navigate from one hovering point to another point in space. However, I’ve encountered significant challenges, and the results have been far from satisfactory.
Could anyone provide suggestions or insights into potential issues that might be causing this? thank you drl, quadcopter, agent MATLAB Answers — New Questions
Matlab question signal processing
Using the EMG file (EMG.txt) that was assigned. The sampling frequency is 1000Hz. Use MATLAB to create a subplot of the EMG signal graphed over time, and an amplitude spectrum of the EMG signal.
a. What frequency has the largest power?
b. In general, muscle fatigue is concentrated at lower frequencies (<50Hz). Comment on the muscle fatigue by calculating the % of power in 0-50Hz vs. the total frequency power spectrum. (<20% no fatigue; 20-40% mid; >40% high)Using the EMG file (EMG.txt) that was assigned. The sampling frequency is 1000Hz. Use MATLAB to create a subplot of the EMG signal graphed over time, and an amplitude spectrum of the EMG signal.
a. What frequency has the largest power?
b. In general, muscle fatigue is concentrated at lower frequencies (<50Hz). Comment on the muscle fatigue by calculating the % of power in 0-50Hz vs. the total frequency power spectrum. (<20% no fatigue; 20-40% mid; >40% high) Using the EMG file (EMG.txt) that was assigned. The sampling frequency is 1000Hz. Use MATLAB to create a subplot of the EMG signal graphed over time, and an amplitude spectrum of the EMG signal.
a. What frequency has the largest power?
b. In general, muscle fatigue is concentrated at lower frequencies (<50Hz). Comment on the muscle fatigue by calculating the % of power in 0-50Hz vs. the total frequency power spectrum. (<20% no fatigue; 20-40% mid; >40% high) digital signal processing MATLAB Answers — New Questions
Error en código LSTM. Error in LSTM code
Hola, el siguiente código arroja el siguiente error:
Hello, the following code throws the following error:
clc
clear
close all
A1 = 0.04;
A4 = 0.04;
B1 = 1.5e-4;
B4 = 1.5e-4;
Kp1 = 3.7E-6;
Kp4 = 3.7E-6;
g = 9.8;
v=[12.6101 1.0688 31.0125 37.5489 12.9138 71.4793 95.7939 32.9065 79.1094 67.4771 11.8518 72.6723 88.3776 1.0488 11.0924 37.6680 91.5542 99.8999 17.8789 18.0891 11.2040 61.0086 41.7771 26.3225 20.9668 19.5812 88.4935 63.5100 62.6202 66.1686 18.5314 62.9590 87.7691 18.6421 64.9118 88.5281 25.8011 59.0359 49.2004 84.0695 6.1159 74.2078 55.8971 43.5178 78.1925 40.2701 36.3657 66.2878 40.0230 18.6693 6.3752 25.4650 90.2795 98.2619 48.9268 15.3302 51.6550 99.3592 76.4943 96.6364 93.0582 24.4126 10.6547 41.5677 13.9861 75.7021 35.4622 45.5286 20.7342 73.9153 21.1334 77.0479 24.8867 61.7596 35.2314 72.5405 12.6051 18.8981 20.1926 36.6943 41.0350 23.3522 67.2367 95.7641 43.7348 80.5776 80.0207 99.5289 21.9686 33.5729 76.4718 75.9192 96.1664 57.4193 61.2421 37.1441 35.0112 60.3988 53.0373 49.0117];
p=[65.9094 4.7869 19.8024 92.9458 58.7150 2.5256 30.0739 5.4808 79.6784 71.4252 54.0998 59.0927 21.8838 41.9776 52.0662 83.9952 66.3312 48.6364 85.4237 48.6713 27.9573 73.3884 96.9775 38.1866 24.6214 25.0278 2.8750 98.2827 80.4593 56.7850 39.4941 65.6003 99.3771 71.6628 11.1343 45.2816 69.5867 33.9626 92.2531 63.6166 93.2864 43.1661 30.7485 89.0138 2.7200 15.6575 95.9571 71.7325 31.3402 82.9815 80.9813 91.0163 64.6385 63.2399 12.7286 91.9783 62.7741 26.5009 95.1791 5.5744 3.0718 9.7170 52.2664 87.9877 40.8157 56.5710 60.2174 8.4300 39.7575 36.1435 25.2341 11.6948 12.1166 27.4533 27.3728 93.6720 19.4315 51.2361 15.6118 92.1493 93.0167 14.5384 87.2854 2.2232 72.4816 87.9799 39.3572 25.3966 12.0606 84.8313 66.3062 78.1866 36.4977 19.2294 2.0078 9.5056 33.6173 30.7822 51.1505 39.2739];
sim_in = [v, p];
sim_out = [7.1311 6.3588 6.0545 7.8257 9.1521 8.0623 7.0667 6.2499 6.0917 6.2498 7.5273 7.2557 6.3734 7.3573 8.4913 9.8310 8.9261 7.8193 10.0257 10.6941 10.6282 10.7414 12.1362 12.1442 11.7505 11.4088 10.1702 10.6450 10.8248 10.4919 10.7776 10.6827 10.0315 11.5522 10.4712 9.5101 10.7533 10.1794 11.1625 10.3909 13.2449 12.4087 11.7282 12.7822 11.4824 10.6570 12.2692 12.0873 11.6660 13.5195 15.6611 17.3295 16.0747 14.6372 13.5176 15.7546 15.6847 14.2223 13.8570 12.4838 11.1820 10.2803 11.2498 12.3825 12.6999 12.0127 12.5235 11.4221 11.6250 10.7953 10.4960 9.4175 8.6992 8.0898 7.8539 8.0031 7.7384 8.6275 8.1134 9.7540 11.1313 10.4081 10.5331 9.3326 10.0847 9.6961 8.9038 7.8016 7.2000 8.8101 8.4298 8.2227 7.2229 6.6039 5.6859 5.0770 5.2510 4.9641 5.2480 5.3237];
v_Datastore = arrayDatastore(v);
p_Datastore = arrayDatastore(p);
out_Datastore=arrayDatastore(sim_out);
trainDatastore = combine(v_Datastore, p_Datastore, out_Datastore);
% —————CREATE END TRAIN NETWORK——————
% Network architecture
numResponses = 1;
featureDimension = 1;
numHiddenUnits = 400;
maxEpochs = 400;
miniBatchSize = 300;
Networklayers = [sequenceInputLayer(featureDimension) …
lstmLayer(numHiddenUnits) …
dropoutLayer(0.02),…
fullyConnectedLayer(numResponses) …
regressionLayer
];
options = trainingOptions(‘adam’, …
‘MaxEpochs’,maxEpochs, …
‘MiniBatchSize’,miniBatchSize, …
‘GradientThreshold’,20, …
‘Shuffle’,’once’, …
‘Plots’,’training-progress’,…
‘LearnRateSchedule’,’piecewise’,…
‘LearnRateDropPeriod’,200,…
‘L2Regularization’,1e-3,…
‘LearnRateDropFactor’,0.5,…
‘Verbose’,0,…
‘ValidationData’,[{sim_in} {sim_out}]);
% ENTRENAMIENTO
net = trainnet(trainDatastore, Networklayers,options);
Falta un argumento en la llamada a la función pero no se cuál poner. Gracias.
There is a missing argument in the function call but I don’t know which one to put. Thank you.
Si pongo trainNetwork el error es:
If I put trainNetwork the error is:
Error using trainNetwork (line 191)
Invalid validation data. Sequence responses must have the same sequence length as the
corresponding predictors.
Error in miso_directo (line 52)
net = trainNetwork(trainDatastore,Networklayers,options);
Tengo dos entradas de 100 elementos y una salida de 100 elementos.
I have two inputs of 100 elements and one output of 100 elements.
Gracias. Thanks.Hola, el siguiente código arroja el siguiente error:
Hello, the following code throws the following error:
clc
clear
close all
A1 = 0.04;
A4 = 0.04;
B1 = 1.5e-4;
B4 = 1.5e-4;
Kp1 = 3.7E-6;
Kp4 = 3.7E-6;
g = 9.8;
v=[12.6101 1.0688 31.0125 37.5489 12.9138 71.4793 95.7939 32.9065 79.1094 67.4771 11.8518 72.6723 88.3776 1.0488 11.0924 37.6680 91.5542 99.8999 17.8789 18.0891 11.2040 61.0086 41.7771 26.3225 20.9668 19.5812 88.4935 63.5100 62.6202 66.1686 18.5314 62.9590 87.7691 18.6421 64.9118 88.5281 25.8011 59.0359 49.2004 84.0695 6.1159 74.2078 55.8971 43.5178 78.1925 40.2701 36.3657 66.2878 40.0230 18.6693 6.3752 25.4650 90.2795 98.2619 48.9268 15.3302 51.6550 99.3592 76.4943 96.6364 93.0582 24.4126 10.6547 41.5677 13.9861 75.7021 35.4622 45.5286 20.7342 73.9153 21.1334 77.0479 24.8867 61.7596 35.2314 72.5405 12.6051 18.8981 20.1926 36.6943 41.0350 23.3522 67.2367 95.7641 43.7348 80.5776 80.0207 99.5289 21.9686 33.5729 76.4718 75.9192 96.1664 57.4193 61.2421 37.1441 35.0112 60.3988 53.0373 49.0117];
p=[65.9094 4.7869 19.8024 92.9458 58.7150 2.5256 30.0739 5.4808 79.6784 71.4252 54.0998 59.0927 21.8838 41.9776 52.0662 83.9952 66.3312 48.6364 85.4237 48.6713 27.9573 73.3884 96.9775 38.1866 24.6214 25.0278 2.8750 98.2827 80.4593 56.7850 39.4941 65.6003 99.3771 71.6628 11.1343 45.2816 69.5867 33.9626 92.2531 63.6166 93.2864 43.1661 30.7485 89.0138 2.7200 15.6575 95.9571 71.7325 31.3402 82.9815 80.9813 91.0163 64.6385 63.2399 12.7286 91.9783 62.7741 26.5009 95.1791 5.5744 3.0718 9.7170 52.2664 87.9877 40.8157 56.5710 60.2174 8.4300 39.7575 36.1435 25.2341 11.6948 12.1166 27.4533 27.3728 93.6720 19.4315 51.2361 15.6118 92.1493 93.0167 14.5384 87.2854 2.2232 72.4816 87.9799 39.3572 25.3966 12.0606 84.8313 66.3062 78.1866 36.4977 19.2294 2.0078 9.5056 33.6173 30.7822 51.1505 39.2739];
sim_in = [v, p];
sim_out = [7.1311 6.3588 6.0545 7.8257 9.1521 8.0623 7.0667 6.2499 6.0917 6.2498 7.5273 7.2557 6.3734 7.3573 8.4913 9.8310 8.9261 7.8193 10.0257 10.6941 10.6282 10.7414 12.1362 12.1442 11.7505 11.4088 10.1702 10.6450 10.8248 10.4919 10.7776 10.6827 10.0315 11.5522 10.4712 9.5101 10.7533 10.1794 11.1625 10.3909 13.2449 12.4087 11.7282 12.7822 11.4824 10.6570 12.2692 12.0873 11.6660 13.5195 15.6611 17.3295 16.0747 14.6372 13.5176 15.7546 15.6847 14.2223 13.8570 12.4838 11.1820 10.2803 11.2498 12.3825 12.6999 12.0127 12.5235 11.4221 11.6250 10.7953 10.4960 9.4175 8.6992 8.0898 7.8539 8.0031 7.7384 8.6275 8.1134 9.7540 11.1313 10.4081 10.5331 9.3326 10.0847 9.6961 8.9038 7.8016 7.2000 8.8101 8.4298 8.2227 7.2229 6.6039 5.6859 5.0770 5.2510 4.9641 5.2480 5.3237];
v_Datastore = arrayDatastore(v);
p_Datastore = arrayDatastore(p);
out_Datastore=arrayDatastore(sim_out);
trainDatastore = combine(v_Datastore, p_Datastore, out_Datastore);
% —————CREATE END TRAIN NETWORK——————
% Network architecture
numResponses = 1;
featureDimension = 1;
numHiddenUnits = 400;
maxEpochs = 400;
miniBatchSize = 300;
Networklayers = [sequenceInputLayer(featureDimension) …
lstmLayer(numHiddenUnits) …
dropoutLayer(0.02),…
fullyConnectedLayer(numResponses) …
regressionLayer
];
options = trainingOptions(‘adam’, …
‘MaxEpochs’,maxEpochs, …
‘MiniBatchSize’,miniBatchSize, …
‘GradientThreshold’,20, …
‘Shuffle’,’once’, …
‘Plots’,’training-progress’,…
‘LearnRateSchedule’,’piecewise’,…
‘LearnRateDropPeriod’,200,…
‘L2Regularization’,1e-3,…
‘LearnRateDropFactor’,0.5,…
‘Verbose’,0,…
‘ValidationData’,[{sim_in} {sim_out}]);
% ENTRENAMIENTO
net = trainnet(trainDatastore, Networklayers,options);
Falta un argumento en la llamada a la función pero no se cuál poner. Gracias.
There is a missing argument in the function call but I don’t know which one to put. Thank you.
Si pongo trainNetwork el error es:
If I put trainNetwork the error is:
Error using trainNetwork (line 191)
Invalid validation data. Sequence responses must have the same sequence length as the
corresponding predictors.
Error in miso_directo (line 52)
net = trainNetwork(trainDatastore,Networklayers,options);
Tengo dos entradas de 100 elementos y una salida de 100 elementos.
I have two inputs of 100 elements and one output of 100 elements.
Gracias. Thanks. Hola, el siguiente código arroja el siguiente error:
Hello, the following code throws the following error:
clc
clear
close all
A1 = 0.04;
A4 = 0.04;
B1 = 1.5e-4;
B4 = 1.5e-4;
Kp1 = 3.7E-6;
Kp4 = 3.7E-6;
g = 9.8;
v=[12.6101 1.0688 31.0125 37.5489 12.9138 71.4793 95.7939 32.9065 79.1094 67.4771 11.8518 72.6723 88.3776 1.0488 11.0924 37.6680 91.5542 99.8999 17.8789 18.0891 11.2040 61.0086 41.7771 26.3225 20.9668 19.5812 88.4935 63.5100 62.6202 66.1686 18.5314 62.9590 87.7691 18.6421 64.9118 88.5281 25.8011 59.0359 49.2004 84.0695 6.1159 74.2078 55.8971 43.5178 78.1925 40.2701 36.3657 66.2878 40.0230 18.6693 6.3752 25.4650 90.2795 98.2619 48.9268 15.3302 51.6550 99.3592 76.4943 96.6364 93.0582 24.4126 10.6547 41.5677 13.9861 75.7021 35.4622 45.5286 20.7342 73.9153 21.1334 77.0479 24.8867 61.7596 35.2314 72.5405 12.6051 18.8981 20.1926 36.6943 41.0350 23.3522 67.2367 95.7641 43.7348 80.5776 80.0207 99.5289 21.9686 33.5729 76.4718 75.9192 96.1664 57.4193 61.2421 37.1441 35.0112 60.3988 53.0373 49.0117];
p=[65.9094 4.7869 19.8024 92.9458 58.7150 2.5256 30.0739 5.4808 79.6784 71.4252 54.0998 59.0927 21.8838 41.9776 52.0662 83.9952 66.3312 48.6364 85.4237 48.6713 27.9573 73.3884 96.9775 38.1866 24.6214 25.0278 2.8750 98.2827 80.4593 56.7850 39.4941 65.6003 99.3771 71.6628 11.1343 45.2816 69.5867 33.9626 92.2531 63.6166 93.2864 43.1661 30.7485 89.0138 2.7200 15.6575 95.9571 71.7325 31.3402 82.9815 80.9813 91.0163 64.6385 63.2399 12.7286 91.9783 62.7741 26.5009 95.1791 5.5744 3.0718 9.7170 52.2664 87.9877 40.8157 56.5710 60.2174 8.4300 39.7575 36.1435 25.2341 11.6948 12.1166 27.4533 27.3728 93.6720 19.4315 51.2361 15.6118 92.1493 93.0167 14.5384 87.2854 2.2232 72.4816 87.9799 39.3572 25.3966 12.0606 84.8313 66.3062 78.1866 36.4977 19.2294 2.0078 9.5056 33.6173 30.7822 51.1505 39.2739];
sim_in = [v, p];
sim_out = [7.1311 6.3588 6.0545 7.8257 9.1521 8.0623 7.0667 6.2499 6.0917 6.2498 7.5273 7.2557 6.3734 7.3573 8.4913 9.8310 8.9261 7.8193 10.0257 10.6941 10.6282 10.7414 12.1362 12.1442 11.7505 11.4088 10.1702 10.6450 10.8248 10.4919 10.7776 10.6827 10.0315 11.5522 10.4712 9.5101 10.7533 10.1794 11.1625 10.3909 13.2449 12.4087 11.7282 12.7822 11.4824 10.6570 12.2692 12.0873 11.6660 13.5195 15.6611 17.3295 16.0747 14.6372 13.5176 15.7546 15.6847 14.2223 13.8570 12.4838 11.1820 10.2803 11.2498 12.3825 12.6999 12.0127 12.5235 11.4221 11.6250 10.7953 10.4960 9.4175 8.6992 8.0898 7.8539 8.0031 7.7384 8.6275 8.1134 9.7540 11.1313 10.4081 10.5331 9.3326 10.0847 9.6961 8.9038 7.8016 7.2000 8.8101 8.4298 8.2227 7.2229 6.6039 5.6859 5.0770 5.2510 4.9641 5.2480 5.3237];
v_Datastore = arrayDatastore(v);
p_Datastore = arrayDatastore(p);
out_Datastore=arrayDatastore(sim_out);
trainDatastore = combine(v_Datastore, p_Datastore, out_Datastore);
% —————CREATE END TRAIN NETWORK——————
% Network architecture
numResponses = 1;
featureDimension = 1;
numHiddenUnits = 400;
maxEpochs = 400;
miniBatchSize = 300;
Networklayers = [sequenceInputLayer(featureDimension) …
lstmLayer(numHiddenUnits) …
dropoutLayer(0.02),…
fullyConnectedLayer(numResponses) …
regressionLayer
];
options = trainingOptions(‘adam’, …
‘MaxEpochs’,maxEpochs, …
‘MiniBatchSize’,miniBatchSize, …
‘GradientThreshold’,20, …
‘Shuffle’,’once’, …
‘Plots’,’training-progress’,…
‘LearnRateSchedule’,’piecewise’,…
‘LearnRateDropPeriod’,200,…
‘L2Regularization’,1e-3,…
‘LearnRateDropFactor’,0.5,…
‘Verbose’,0,…
‘ValidationData’,[{sim_in} {sim_out}]);
% ENTRENAMIENTO
net = trainnet(trainDatastore, Networklayers,options);
Falta un argumento en la llamada a la función pero no se cuál poner. Gracias.
There is a missing argument in the function call but I don’t know which one to put. Thank you.
Si pongo trainNetwork el error es:
If I put trainNetwork the error is:
Error using trainNetwork (line 191)
Invalid validation data. Sequence responses must have the same sequence length as the
corresponding predictors.
Error in miso_directo (line 52)
net = trainNetwork(trainDatastore,Networklayers,options);
Tengo dos entradas de 100 elementos y una salida de 100 elementos.
I have two inputs of 100 elements and one output of 100 elements.
Gracias. Thanks. transferred MATLAB Answers — New Questions
Indexing of cell array and a vector
Hi guys, my problem has been raised before but with some differences.
I have a cell array of indexes, index. Its cells can be zero or vectors with several values. On the other hand I have a data vector, data. I need a cell array, out, that relates data to indexes, preferably without using a loop.
For example:
index = {[0], [0], [5], [0], [6, 7], [0], [0], [1], [0], [0], [0], [ 3]} ;
data = [100, 10, 20, 15, 11, 25, 200, 45];
Desired result:
out = {[0], [0], [11], [0], [25, 200], [0], [0], [100], [0], [0], [20]}
Can somebody help me?Hi guys, my problem has been raised before but with some differences.
I have a cell array of indexes, index. Its cells can be zero or vectors with several values. On the other hand I have a data vector, data. I need a cell array, out, that relates data to indexes, preferably without using a loop.
For example:
index = {[0], [0], [5], [0], [6, 7], [0], [0], [1], [0], [0], [0], [ 3]} ;
data = [100, 10, 20, 15, 11, 25, 200, 45];
Desired result:
out = {[0], [0], [11], [0], [25, 200], [0], [0], [100], [0], [0], [20]}
Can somebody help me? Hi guys, my problem has been raised before but with some differences.
I have a cell array of indexes, index. Its cells can be zero or vectors with several values. On the other hand I have a data vector, data. I need a cell array, out, that relates data to indexes, preferably without using a loop.
For example:
index = {[0], [0], [5], [0], [6, 7], [0], [0], [1], [0], [0], [0], [ 3]} ;
data = [100, 10, 20, 15, 11, 25, 200, 45];
Desired result:
out = {[0], [0], [11], [0], [25, 200], [0], [0], [100], [0], [0], [20]}
Can somebody help me? cell array, indexing MATLAB Answers — New Questions
Is it possible to export measurement reading of Signal Statistics in Simulink Scope block to workspace? If it is possible, then how?
Hello and thank you for you concern Sir. As mention above, I’m fully aware about the method on data logging from the scope display to workspace. However, the logging only record/export the simulation signal data to our workspace. Refer to image that i attached, the scope able to determine the Max, Min, Peak to peak, Median and RMS value for the simulation. These reading is in the Signal Statistics section if the scope display enable it from Tools>Measurement>Signal Statistics.
My motivation is to obtain the RMS value recorded in the scope and export it to workspace or save it to a file or etc. It is because I’m dealing with multiple/repitative simulations with different parameters just to observe the changes of the RMS value. Hence, is there any possible way to export the readings? or any possible way for me to obtain RMS value of the simulation.
Notes: I had try the RMS block in the simulink, however it did not provide the correct measurement. I think this happen due to my sample data if from discharging of battery model (DC current). Maybe, I’m not verry sure. Sorry.
Anyway, thank you in advance if someone able to help me on this. I really appriciate your concern Sir.Hello and thank you for you concern Sir. As mention above, I’m fully aware about the method on data logging from the scope display to workspace. However, the logging only record/export the simulation signal data to our workspace. Refer to image that i attached, the scope able to determine the Max, Min, Peak to peak, Median and RMS value for the simulation. These reading is in the Signal Statistics section if the scope display enable it from Tools>Measurement>Signal Statistics.
My motivation is to obtain the RMS value recorded in the scope and export it to workspace or save it to a file or etc. It is because I’m dealing with multiple/repitative simulations with different parameters just to observe the changes of the RMS value. Hence, is there any possible way to export the readings? or any possible way for me to obtain RMS value of the simulation.
Notes: I had try the RMS block in the simulink, however it did not provide the correct measurement. I think this happen due to my sample data if from discharging of battery model (DC current). Maybe, I’m not verry sure. Sorry.
Anyway, thank you in advance if someone able to help me on this. I really appriciate your concern Sir. Hello and thank you for you concern Sir. As mention above, I’m fully aware about the method on data logging from the scope display to workspace. However, the logging only record/export the simulation signal data to our workspace. Refer to image that i attached, the scope able to determine the Max, Min, Peak to peak, Median and RMS value for the simulation. These reading is in the Signal Statistics section if the scope display enable it from Tools>Measurement>Signal Statistics.
My motivation is to obtain the RMS value recorded in the scope and export it to workspace or save it to a file or etc. It is because I’m dealing with multiple/repitative simulations with different parameters just to observe the changes of the RMS value. Hence, is there any possible way to export the readings? or any possible way for me to obtain RMS value of the simulation.
Notes: I had try the RMS block in the simulink, however it did not provide the correct measurement. I think this happen due to my sample data if from discharging of battery model (DC current). Maybe, I’m not verry sure. Sorry.
Anyway, thank you in advance if someone able to help me on this. I really appriciate your concern Sir. simulink, scope block, signal statistics, rms value MATLAB Answers — New Questions
Comparison of Crossover Methods: ‘crossoverheuristic’ vs ‘crossoverintermediate’ vs ‘crossoverarithmetic’
How is ‘crossoverheuristic’ different from ‘crossoverintermediate’?
Is that ‘crossoverheuristic’ always take ratio greater than 1, i.e., the offspring will always be much far from the parent with lower fitness compared to the parent with higher fitness?
Is ‘crossoverheuristic’ a special case of ‘crossoverintermediate’?
Should the ratio be always scalar in ‘crossoverheuristic’?
Is there any issue in setting the ratio to greater than 1 for ‘crossoverintermediate’ over a problem with linear constraints and bounds?
How is ‘crossoverarithmetic’ different from ‘crossoverintermediate’?How is ‘crossoverheuristic’ different from ‘crossoverintermediate’?
Is that ‘crossoverheuristic’ always take ratio greater than 1, i.e., the offspring will always be much far from the parent with lower fitness compared to the parent with higher fitness?
Is ‘crossoverheuristic’ a special case of ‘crossoverintermediate’?
Should the ratio be always scalar in ‘crossoverheuristic’?
Is there any issue in setting the ratio to greater than 1 for ‘crossoverintermediate’ over a problem with linear constraints and bounds?
How is ‘crossoverarithmetic’ different from ‘crossoverintermediate’? How is ‘crossoverheuristic’ different from ‘crossoverintermediate’?
Is that ‘crossoverheuristic’ always take ratio greater than 1, i.e., the offspring will always be much far from the parent with lower fitness compared to the parent with higher fitness?
Is ‘crossoverheuristic’ a special case of ‘crossoverintermediate’?
Should the ratio be always scalar in ‘crossoverheuristic’?
Is there any issue in setting the ratio to greater than 1 for ‘crossoverintermediate’ over a problem with linear constraints and bounds?
How is ‘crossoverarithmetic’ different from ‘crossoverintermediate’? ga, gamultiobj, crossover, genetic algorithm MATLAB Answers — New Questions
How to save entire MATLAB workspace as a JSON file?
Hi everyone, I need to export my MATLAB workspace as a JSON file.
From what I can see, the standard save command wouldn’t be useful here.
And the jsonencode help doesn’t tell you how to save the entire workspace as a JSON file:
Create JSON-formatted text from structured MATLAB data – MATLAB jsonencode – MathWorks United Kingdom
Any help on how to achieve this would be much appreciatedHi everyone, I need to export my MATLAB workspace as a JSON file.
From what I can see, the standard save command wouldn’t be useful here.
And the jsonencode help doesn’t tell you how to save the entire workspace as a JSON file:
Create JSON-formatted text from structured MATLAB data – MATLAB jsonencode – MathWorks United Kingdom
Any help on how to achieve this would be much appreciated Hi everyone, I need to export my MATLAB workspace as a JSON file.
From what I can see, the standard save command wouldn’t be useful here.
And the jsonencode help doesn’t tell you how to save the entire workspace as a JSON file:
Create JSON-formatted text from structured MATLAB data – MATLAB jsonencode – MathWorks United Kingdom
Any help on how to achieve this would be much appreciated json MATLAB Answers — New Questions
i am trying to run biped robot and it is giving following error: Error using rlRepresentation (line 70) rlRepresentation will be removed in a future release. Unable to automat
i am trying to run biped robot and it is giving following error:
Error using rlRepresentation (line 70) rlRepresentation will be removed in a future release. Unable to automatically convert rlRepresentation to new representation object. Use the new representation objects rlValueRepresentation, rlQValueRepresentation, rlDeterministicActorRepresentation, or rlStochasticActorRepresentation instead.i am trying to run biped robot and it is giving following error:
Error using rlRepresentation (line 70) rlRepresentation will be removed in a future release. Unable to automatically convert rlRepresentation to new representation object. Use the new representation objects rlValueRepresentation, rlQValueRepresentation, rlDeterministicActorRepresentation, or rlStochasticActorRepresentation instead. i am trying to run biped robot and it is giving following error:
Error using rlRepresentation (line 70) rlRepresentation will be removed in a future release. Unable to automatically convert rlRepresentation to new representation object. Use the new representation objects rlValueRepresentation, rlQValueRepresentation, rlDeterministicActorRepresentation, or rlStochasticActorRepresentation instead. rl represetation MATLAB Answers — New Questions
Is the state variable x a column vector or a row vector?
In a state space equation such as xdot=Ax+Bu, if the system has only two state variables, x1 and x2, shouldn’t the x matrix be just a 2*1 matrix? Suppose I control the system by means of an LQR linear controller and get the corresponding results for the state variables x1 and x2, at this point I want to represent them by means of an image. At this point I just want to know the representation of x1 in the image, is it correct to use the plot(t,x(:,1)); statement. If the plotting is correct at this point, but x(:,1) is queried in the help as referring to the elements of all rows in the first column of the matrix, this suggests that the value of x1 is stored in the first column of the x matrix, but as stated at the beginning the x matrix should be a 2 row, 1 column matrix.
About why the plot(t,x(:,1)); statement is used to get the image of x1 is something I can’t understand at the moment.
Hope someone can help me with this query, thanks a lot!!!!
Translated with www.DeepL.com/Translator (free version)
clc;clear;close all;
%% 定义参数
g=10;
d=1;
%% 定义矩阵
A=[0 1;g/d 0];
B=[0;1];
C = [1, 0];
D = 0;
%% 建立状态空间方程表达式
sys = ss(A,B,C,D);
%% 定义初始状态
z0=[pi/20;0];
%% 定义权重系数,求K
q1=[100 0;0 1];
r1=1;
[K1, z, l] = lqr (sys, q1, r1);
q2=[1 0;0 100];
r2=1;
[K2, z, l] = lqr (sys, q2, r2);
q3=[1 0;0 1];
r3=100;
[K3, z, l] = lqr (sys, q3, r3);
%% 定义闭环系统
sys_cl1=ss(A-B*K1,[0;0],C,D);
sys_cl2=ss(A-B*K2,[0;0],C,D);
sys_cl3=ss(A-B*K3,[0;0],C,D);
%% 仿真
%% 对初始条件的响应
t=0:0.01:5;
[y1,t,z1]=initial(sys_cl1,z0,t);
[y2,t,z2]=initial(sys_cl2,z0,t);
[y3,t,z3]=initial(sys_cl3,z0,t);
%% 绘图
%% 状态变量1
subplot(3,1,1);
plot(t,z1(:,1));
hold on;
plot(t,z2(:,1));
hold on;
plot(t,z3(:,1));
legend(‘z1_1′,’z1_2′,’z1_3’);
grid on;
hold off;
%% 状态变量2
subplot(3,1,2);
plot(t,z1(:,2));
hold on;
plot(t,z2(:,2));
hold on;
plot(t,z3(:,2));
legend(‘z2_1′,’z2_2′,’z2_3’);
grid on;
hold off;
%% 系统输入
subplot(3,1,3);
plot(t,-K1*z1′);
hold on;
plot(t,-K2*z3′);
hold on;
plot(t,-K3*z3′);
legend(‘u_1′,’u_2′,’u_3’);
grid on;
hold off;In a state space equation such as xdot=Ax+Bu, if the system has only two state variables, x1 and x2, shouldn’t the x matrix be just a 2*1 matrix? Suppose I control the system by means of an LQR linear controller and get the corresponding results for the state variables x1 and x2, at this point I want to represent them by means of an image. At this point I just want to know the representation of x1 in the image, is it correct to use the plot(t,x(:,1)); statement. If the plotting is correct at this point, but x(:,1) is queried in the help as referring to the elements of all rows in the first column of the matrix, this suggests that the value of x1 is stored in the first column of the x matrix, but as stated at the beginning the x matrix should be a 2 row, 1 column matrix.
About why the plot(t,x(:,1)); statement is used to get the image of x1 is something I can’t understand at the moment.
Hope someone can help me with this query, thanks a lot!!!!
Translated with www.DeepL.com/Translator (free version)
clc;clear;close all;
%% 定义参数
g=10;
d=1;
%% 定义矩阵
A=[0 1;g/d 0];
B=[0;1];
C = [1, 0];
D = 0;
%% 建立状态空间方程表达式
sys = ss(A,B,C,D);
%% 定义初始状态
z0=[pi/20;0];
%% 定义权重系数,求K
q1=[100 0;0 1];
r1=1;
[K1, z, l] = lqr (sys, q1, r1);
q2=[1 0;0 100];
r2=1;
[K2, z, l] = lqr (sys, q2, r2);
q3=[1 0;0 1];
r3=100;
[K3, z, l] = lqr (sys, q3, r3);
%% 定义闭环系统
sys_cl1=ss(A-B*K1,[0;0],C,D);
sys_cl2=ss(A-B*K2,[0;0],C,D);
sys_cl3=ss(A-B*K3,[0;0],C,D);
%% 仿真
%% 对初始条件的响应
t=0:0.01:5;
[y1,t,z1]=initial(sys_cl1,z0,t);
[y2,t,z2]=initial(sys_cl2,z0,t);
[y3,t,z3]=initial(sys_cl3,z0,t);
%% 绘图
%% 状态变量1
subplot(3,1,1);
plot(t,z1(:,1));
hold on;
plot(t,z2(:,1));
hold on;
plot(t,z3(:,1));
legend(‘z1_1′,’z1_2′,’z1_3’);
grid on;
hold off;
%% 状态变量2
subplot(3,1,2);
plot(t,z1(:,2));
hold on;
plot(t,z2(:,2));
hold on;
plot(t,z3(:,2));
legend(‘z2_1′,’z2_2′,’z2_3’);
grid on;
hold off;
%% 系统输入
subplot(3,1,3);
plot(t,-K1*z1′);
hold on;
plot(t,-K2*z3′);
hold on;
plot(t,-K3*z3′);
legend(‘u_1′,’u_2′,’u_3’);
grid on;
hold off; In a state space equation such as xdot=Ax+Bu, if the system has only two state variables, x1 and x2, shouldn’t the x matrix be just a 2*1 matrix? Suppose I control the system by means of an LQR linear controller and get the corresponding results for the state variables x1 and x2, at this point I want to represent them by means of an image. At this point I just want to know the representation of x1 in the image, is it correct to use the plot(t,x(:,1)); statement. If the plotting is correct at this point, but x(:,1) is queried in the help as referring to the elements of all rows in the first column of the matrix, this suggests that the value of x1 is stored in the first column of the x matrix, but as stated at the beginning the x matrix should be a 2 row, 1 column matrix.
About why the plot(t,x(:,1)); statement is used to get the image of x1 is something I can’t understand at the moment.
Hope someone can help me with this query, thanks a lot!!!!
Translated with www.DeepL.com/Translator (free version)
clc;clear;close all;
%% 定义参数
g=10;
d=1;
%% 定义矩阵
A=[0 1;g/d 0];
B=[0;1];
C = [1, 0];
D = 0;
%% 建立状态空间方程表达式
sys = ss(A,B,C,D);
%% 定义初始状态
z0=[pi/20;0];
%% 定义权重系数,求K
q1=[100 0;0 1];
r1=1;
[K1, z, l] = lqr (sys, q1, r1);
q2=[1 0;0 100];
r2=1;
[K2, z, l] = lqr (sys, q2, r2);
q3=[1 0;0 1];
r3=100;
[K3, z, l] = lqr (sys, q3, r3);
%% 定义闭环系统
sys_cl1=ss(A-B*K1,[0;0],C,D);
sys_cl2=ss(A-B*K2,[0;0],C,D);
sys_cl3=ss(A-B*K3,[0;0],C,D);
%% 仿真
%% 对初始条件的响应
t=0:0.01:5;
[y1,t,z1]=initial(sys_cl1,z0,t);
[y2,t,z2]=initial(sys_cl2,z0,t);
[y3,t,z3]=initial(sys_cl3,z0,t);
%% 绘图
%% 状态变量1
subplot(3,1,1);
plot(t,z1(:,1));
hold on;
plot(t,z2(:,1));
hold on;
plot(t,z3(:,1));
legend(‘z1_1′,’z1_2′,’z1_3’);
grid on;
hold off;
%% 状态变量2
subplot(3,1,2);
plot(t,z1(:,2));
hold on;
plot(t,z2(:,2));
hold on;
plot(t,z3(:,2));
legend(‘z2_1′,’z2_2′,’z2_3’);
grid on;
hold off;
%% 系统输入
subplot(3,1,3);
plot(t,-K1*z1′);
hold on;
plot(t,-K2*z3′);
hold on;
plot(t,-K3*z3′);
legend(‘u_1′,’u_2′,’u_3’);
grid on;
hold off; state space, vector MATLAB Answers — New Questions