Category: Matlab
Category Archives: Matlab
How to reach train and test and their predictions in nftool?
I have conducted neural network on my dataset with 228 rows and 7 columns but don’t know how to obtain my training and testing datasets and their prediction values. I want to export this values.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 20-Jul-2024 16:31:01
%
% This script assumes these variables are defined:
%
% data – input data.
% data_1 – target data.
x = data’;
t = data_1′;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 4;
net = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)I have conducted neural network on my dataset with 228 rows and 7 columns but don’t know how to obtain my training and testing datasets and their prediction values. I want to export this values.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 20-Jul-2024 16:31:01
%
% This script assumes these variables are defined:
%
% data – input data.
% data_1 – target data.
x = data’;
t = data_1′;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 4;
net = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t) I have conducted neural network on my dataset with 228 rows and 7 columns but don’t know how to obtain my training and testing datasets and their prediction values. I want to export this values.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 20-Jul-2024 16:31:01
%
% This script assumes these variables are defined:
%
% data – input data.
% data_1 – target data.
x = data’;
t = data_1′;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 4;
net = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t) nftool, train, test, predictions, export results MATLAB Answers — New Questions
How can I remove a line off UIAxes on App designer in RealTime with SpeedGoat
Hi,
Im creating an app using App designer and Simulink in Realtime with a speedgoat. I have a drop down menu that has a selection of position or velocity. Depending on what is selected I want to plot it on a UIaxes. However, for instance, when I go from velocity to poisition or vice versa, The graph keeps both lines on the UIAxes. I only need to show one line that corresponds to the value of the dropdown list. Im using connectline() command to plot. I tried using clearScalarAndLineData() command to clear the axes but it is not working. My issue is that I cannot get rid of a line once I use the connectline() command. I also tried using cla() but once I use it, it will not replot during the simulation.
My desire is to have when the dropdown list equals to position, the UIaxes will plot only the position signal and when the dropdown list equals velocity, it will only plot the velocity signal during simulation.
Here is my code so far
function PlotSelectValueChanged(app, event)
value = app.PlotSelect.Value;
if value == "Position"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Pos_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
elseif value == "velocity"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Vel_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
end
end
ThanksHi,
Im creating an app using App designer and Simulink in Realtime with a speedgoat. I have a drop down menu that has a selection of position or velocity. Depending on what is selected I want to plot it on a UIaxes. However, for instance, when I go from velocity to poisition or vice versa, The graph keeps both lines on the UIAxes. I only need to show one line that corresponds to the value of the dropdown list. Im using connectline() command to plot. I tried using clearScalarAndLineData() command to clear the axes but it is not working. My issue is that I cannot get rid of a line once I use the connectline() command. I also tried using cla() but once I use it, it will not replot during the simulation.
My desire is to have when the dropdown list equals to position, the UIaxes will plot only the position signal and when the dropdown list equals velocity, it will only plot the velocity signal during simulation.
Here is my code so far
function PlotSelectValueChanged(app, event)
value = app.PlotSelect.Value;
if value == "Position"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Pos_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
elseif value == "velocity"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Vel_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
end
end
Thanks Hi,
Im creating an app using App designer and Simulink in Realtime with a speedgoat. I have a drop down menu that has a selection of position or velocity. Depending on what is selected I want to plot it on a UIaxes. However, for instance, when I go from velocity to poisition or vice versa, The graph keeps both lines on the UIAxes. I only need to show one line that corresponds to the value of the dropdown list. Im using connectline() command to plot. I tried using clearScalarAndLineData() command to clear the axes but it is not working. My issue is that I cannot get rid of a line once I use the connectline() command. I also tried using cla() but once I use it, it will not replot during the simulation.
My desire is to have when the dropdown list equals to position, the UIaxes will plot only the position signal and when the dropdown list equals velocity, it will only plot the velocity signal during simulation.
Here is my code so far
function PlotSelectValueChanged(app, event)
value = app.PlotSelect.Value;
if value == "Position"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Pos_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
elseif value == "velocity"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Vel_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
end
end
Thanks simulink, appdesigner MATLAB Answers — New Questions
How to set up a solar water heating system?
I did not find solar heating in the case of simscape, it was only photovoltaic power generation.I did not find solar heating in the case of simscape, it was only photovoltaic power generation. I did not find solar heating in the case of simscape, it was only photovoltaic power generation. simscape, solar, thermal MATLAB Answers — New Questions
Hello all, kindly, I have question , how can I get the piecewise function of this blood flow rate shown below using Matlab
Hello all, kindly, I have question , how can I get the piecewise function of this blood flow rate shown below using MatlabHello all, kindly, I have question , how can I get the piecewise function of this blood flow rate shown below using Matlab Hello all, kindly, I have question , how can I get the piecewise function of this blood flow rate shown below using Matlab curve fitting MATLAB Answers — New Questions
Spatial phase distribution is oppositely observed for imagesc and pcolor plots
clc;
[x,y] = meshgrid(linspace(-0.6, 0.6), linspace(-0.6, 0.6));
[phi,r] = cart2pol(x,y);
% Omega_r -vortex beam specification
l = 2;
p = 2;
w0 = 0.2;
R = sqrt(2).*r./w0;
RR = r./w0;
Omega01 = exp(-RR.^2);
Lpl = 0;
for m = 0:p;
Lpl = Lpl + (((-1).^m)./factorial(m)).*nchoosek(p+l,p-m).*(R.^(2.*m));
end;
Omega_r = Omega01.*(RR.^(abs(l))).*Lpl.*exp(-i.*l.*phi);
%figure;
%imagesc(angle(Omega_r));
%colormap jet
%colorbar
pcolor(x, y, angle(Omega_r))
shading interp
colormap jet
colorbarclc;
[x,y] = meshgrid(linspace(-0.6, 0.6), linspace(-0.6, 0.6));
[phi,r] = cart2pol(x,y);
% Omega_r -vortex beam specification
l = 2;
p = 2;
w0 = 0.2;
R = sqrt(2).*r./w0;
RR = r./w0;
Omega01 = exp(-RR.^2);
Lpl = 0;
for m = 0:p;
Lpl = Lpl + (((-1).^m)./factorial(m)).*nchoosek(p+l,p-m).*(R.^(2.*m));
end;
Omega_r = Omega01.*(RR.^(abs(l))).*Lpl.*exp(-i.*l.*phi);
%figure;
%imagesc(angle(Omega_r));
%colormap jet
%colorbar
pcolor(x, y, angle(Omega_r))
shading interp
colormap jet
colorbar clc;
[x,y] = meshgrid(linspace(-0.6, 0.6), linspace(-0.6, 0.6));
[phi,r] = cart2pol(x,y);
% Omega_r -vortex beam specification
l = 2;
p = 2;
w0 = 0.2;
R = sqrt(2).*r./w0;
RR = r./w0;
Omega01 = exp(-RR.^2);
Lpl = 0;
for m = 0:p;
Lpl = Lpl + (((-1).^m)./factorial(m)).*nchoosek(p+l,p-m).*(R.^(2.*m));
end;
Omega_r = Omega01.*(RR.^(abs(l))).*Lpl.*exp(-i.*l.*phi);
%figure;
%imagesc(angle(Omega_r));
%colormap jet
%colorbar
pcolor(x, y, angle(Omega_r))
shading interp
colormap jet
colorbar iamgesc, pcolor, spatial phase distribution MATLAB Answers — New Questions
I read a 3d image in matlab and converts to a matrix of size 100036*3.Now i want to find correlation coefficient of this matrix separately in x,y &z direction in matlab
I want to find correlaion coefficient in different directions separately .But for finding correlation coefficient i need two variable.So how i can find correlation coefficients in x- direction, y-direction and z-direction separatelyI want to find correlaion coefficient in different directions separately .But for finding correlation coefficient i need two variable.So how i can find correlation coefficients in x- direction, y-direction and z-direction separately I want to find correlaion coefficient in different directions separately .But for finding correlation coefficient i need two variable.So how i can find correlation coefficients in x- direction, y-direction and z-direction separately 3d image encryption MATLAB Answers — New Questions
Is ‘Arduino Nano 33 BLE Sense Rev2’ hardware board compatible with Simulink?
Is ‘Arduino Nano 33 BLE Sense Rev2’ hardware board compatible with Simulink? I tried a Simulink demo model (simple on off the inbuilt led on the Arduino Nano 33 BLE Sense Rev2 hardware board) to verify my board connection with Simulink and I found the following error message in the Simulink Doagnostic Viewer.
Caused by:
Failed to detect host COM port of Nano 33 BLE board.
Install or update the Arduino board driver and try again.Is ‘Arduino Nano 33 BLE Sense Rev2’ hardware board compatible with Simulink? I tried a Simulink demo model (simple on off the inbuilt led on the Arduino Nano 33 BLE Sense Rev2 hardware board) to verify my board connection with Simulink and I found the following error message in the Simulink Doagnostic Viewer.
Caused by:
Failed to detect host COM port of Nano 33 BLE board.
Install or update the Arduino board driver and try again. Is ‘Arduino Nano 33 BLE Sense Rev2’ hardware board compatible with Simulink? I tried a Simulink demo model (simple on off the inbuilt led on the Arduino Nano 33 BLE Sense Rev2 hardware board) to verify my board connection with Simulink and I found the following error message in the Simulink Doagnostic Viewer.
Caused by:
Failed to detect host COM port of Nano 33 BLE board.
Install or update the Arduino board driver and try again. arduino nano 33 ble sense rev2 MATLAB Answers — New Questions
gmake: *** No rule to make target
I created a Simulink model and I am trying to upload to an Arduino, but I keep getting this error:
### Invoking Target Language Compiler on Pixy2CameraModel1.rtw
### Using System Target File: c:appsmatlab2017artwcertert.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
.
### Caching model source code
### Writing header file Pixy2CameraModel1.h
### Writing header file Pixy2CameraModel1_types.h
.
### Writing header file rtwtypes.h
### Writing source file Pixy2CameraModel1.c
### Writing header file Pixy2CameraModel1_private.h
### Writing source file ert_main.c
### TLC code generation complete.
### Creating HTML report file Pixy2CameraModel1_codegen_rpt.html
### Invoking custom build hook: CodeGenBeforeMake
### Using toolchain: Arduino AVR v1.6.13 | gmake (64-bit Windows)
### ‘W:DesktopPixy2TrialPixy2CameraModel1_ert_rtwPixy2CameraModel1.mk’ is up to date
### Building ‘Pixy2CameraModel1’: "C:appsMATLAB~2binwin64gmake" -f Pixy2CameraModel1.mk all
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>cd .
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>if "" == "" ("C:appsMATLAB~2binwin64gmake" -f Pixy2CameraModel1.mk all ) else ("C:appsMATLAB~2binwin64gmake" -f Pixy2CameraModel1.mk )
gmake: *** No rule to make target `W:/Desktop/Pixy2Trial/blocks/src/Pixy2Cam.cpp’, needed by `Pixy2Cam.o’. Stop.
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>echo The make command returned an error of 2
The make command returned an error of 2
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>An_error_occurred_during_the_call_to_make
‘An_error_occurred_during_the_call_to_make’ is not recognized as an internal or external command,
operable program or batch file.
### Build procedure for model: ‘Pixy2CameraModel1’ aborted due to an error.
Error(s) encountered while building "Pixy2CameraModel1":
### Failed to generate all binary outputs.
Component:Simulink | Category:Block diagram errorI created a Simulink model and I am trying to upload to an Arduino, but I keep getting this error:
### Invoking Target Language Compiler on Pixy2CameraModel1.rtw
### Using System Target File: c:appsmatlab2017artwcertert.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
.
### Caching model source code
### Writing header file Pixy2CameraModel1.h
### Writing header file Pixy2CameraModel1_types.h
.
### Writing header file rtwtypes.h
### Writing source file Pixy2CameraModel1.c
### Writing header file Pixy2CameraModel1_private.h
### Writing source file ert_main.c
### TLC code generation complete.
### Creating HTML report file Pixy2CameraModel1_codegen_rpt.html
### Invoking custom build hook: CodeGenBeforeMake
### Using toolchain: Arduino AVR v1.6.13 | gmake (64-bit Windows)
### ‘W:DesktopPixy2TrialPixy2CameraModel1_ert_rtwPixy2CameraModel1.mk’ is up to date
### Building ‘Pixy2CameraModel1’: "C:appsMATLAB~2binwin64gmake" -f Pixy2CameraModel1.mk all
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>cd .
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>if "" == "" ("C:appsMATLAB~2binwin64gmake" -f Pixy2CameraModel1.mk all ) else ("C:appsMATLAB~2binwin64gmake" -f Pixy2CameraModel1.mk )
gmake: *** No rule to make target `W:/Desktop/Pixy2Trial/blocks/src/Pixy2Cam.cpp’, needed by `Pixy2Cam.o’. Stop.
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>echo The make command returned an error of 2
The make command returned an error of 2
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>An_error_occurred_during_the_call_to_make
‘An_error_occurred_during_the_call_to_make’ is not recognized as an internal or external command,
operable program or batch file.
### Build procedure for model: ‘Pixy2CameraModel1’ aborted due to an error.
Error(s) encountered while building "Pixy2CameraModel1":
### Failed to generate all binary outputs.
Component:Simulink | Category:Block diagram error I created a Simulink model and I am trying to upload to an Arduino, but I keep getting this error:
### Invoking Target Language Compiler on Pixy2CameraModel1.rtw
### Using System Target File: c:appsmatlab2017artwcertert.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
.
### Caching model source code
### Writing header file Pixy2CameraModel1.h
### Writing header file Pixy2CameraModel1_types.h
.
### Writing header file rtwtypes.h
### Writing source file Pixy2CameraModel1.c
### Writing header file Pixy2CameraModel1_private.h
### Writing source file ert_main.c
### TLC code generation complete.
### Creating HTML report file Pixy2CameraModel1_codegen_rpt.html
### Invoking custom build hook: CodeGenBeforeMake
### Using toolchain: Arduino AVR v1.6.13 | gmake (64-bit Windows)
### ‘W:DesktopPixy2TrialPixy2CameraModel1_ert_rtwPixy2CameraModel1.mk’ is up to date
### Building ‘Pixy2CameraModel1’: "C:appsMATLAB~2binwin64gmake" -f Pixy2CameraModel1.mk all
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>cd .
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>if "" == "" ("C:appsMATLAB~2binwin64gmake" -f Pixy2CameraModel1.mk all ) else ("C:appsMATLAB~2binwin64gmake" -f Pixy2CameraModel1.mk )
gmake: *** No rule to make target `W:/Desktop/Pixy2Trial/blocks/src/Pixy2Cam.cpp’, needed by `Pixy2Cam.o’. Stop.
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>echo The make command returned an error of 2
The make command returned an error of 2
W:DesktopPixy2TrialPixy2CameraModel1_ert_rtw>An_error_occurred_during_the_call_to_make
‘An_error_occurred_during_the_call_to_make’ is not recognized as an internal or external command,
operable program or batch file.
### Build procedure for model: ‘Pixy2CameraModel1’ aborted due to an error.
Error(s) encountered while building "Pixy2CameraModel1":
### Failed to generate all binary outputs.
Component:Simulink | Category:Block diagram error matlab, simulink MATLAB Answers — New Questions
How to play video in matlab for computer vision?
I am trying to do object recognition using blob analysis. when i did write the code the video is flickering every second, is it possible to have a video player running without flickering? I have attached my code below. please recommend me any changes
%% Setup of video
vidReader=vision.VideoFileReader(‘vidf.mp4’);
vidReader.VideoOutputDataType=’double’;
%% structural element
diskelem=strel(‘disk’,22);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,200,’MaximumBlobArea’,4000);
while ~isDone(vidReader)
%read frame
vidframe=step(vidReader);
%rgb to hsv color space
I=rgb2hsv(vidframe);
%htextins=insertText(I,’position’,[20,20],’Color’,[255 255 0],’Fontsize’,30);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.091;
channel1Max = 0.234;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.309;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & …
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & …
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
%using morphological operations
ibwopen=imopen(BW,diskelem);
%extract the blobs from the frame
[areaOut,centroidOut, bboxOut]=step(hblob,ibwopen);
%draw a box around detected objects
% ishape=insertShape(vidframe,’Rectangle’,bboxOut,’ShapeColor’,’black’);
iannotate = insertObjectAnnotation(vidframe,"rectangle",bboxOut,’banana’,TextBoxOpacity=0.9,FontSize=18);
%paly in video player
vidPlayer = vision.DeployableVideoPlayer;
%step(vidPlayer,ishape);
step(vidPlayer,iannotate);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
%release(ishape)I am trying to do object recognition using blob analysis. when i did write the code the video is flickering every second, is it possible to have a video player running without flickering? I have attached my code below. please recommend me any changes
%% Setup of video
vidReader=vision.VideoFileReader(‘vidf.mp4’);
vidReader.VideoOutputDataType=’double’;
%% structural element
diskelem=strel(‘disk’,22);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,200,’MaximumBlobArea’,4000);
while ~isDone(vidReader)
%read frame
vidframe=step(vidReader);
%rgb to hsv color space
I=rgb2hsv(vidframe);
%htextins=insertText(I,’position’,[20,20],’Color’,[255 255 0],’Fontsize’,30);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.091;
channel1Max = 0.234;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.309;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & …
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & …
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
%using morphological operations
ibwopen=imopen(BW,diskelem);
%extract the blobs from the frame
[areaOut,centroidOut, bboxOut]=step(hblob,ibwopen);
%draw a box around detected objects
% ishape=insertShape(vidframe,’Rectangle’,bboxOut,’ShapeColor’,’black’);
iannotate = insertObjectAnnotation(vidframe,"rectangle",bboxOut,’banana’,TextBoxOpacity=0.9,FontSize=18);
%paly in video player
vidPlayer = vision.DeployableVideoPlayer;
%step(vidPlayer,ishape);
step(vidPlayer,iannotate);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
%release(ishape) I am trying to do object recognition using blob analysis. when i did write the code the video is flickering every second, is it possible to have a video player running without flickering? I have attached my code below. please recommend me any changes
%% Setup of video
vidReader=vision.VideoFileReader(‘vidf.mp4’);
vidReader.VideoOutputDataType=’double’;
%% structural element
diskelem=strel(‘disk’,22);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,200,’MaximumBlobArea’,4000);
while ~isDone(vidReader)
%read frame
vidframe=step(vidReader);
%rgb to hsv color space
I=rgb2hsv(vidframe);
%htextins=insertText(I,’position’,[20,20],’Color’,[255 255 0],’Fontsize’,30);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.091;
channel1Max = 0.234;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.309;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & …
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & …
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
%using morphological operations
ibwopen=imopen(BW,diskelem);
%extract the blobs from the frame
[areaOut,centroidOut, bboxOut]=step(hblob,ibwopen);
%draw a box around detected objects
% ishape=insertShape(vidframe,’Rectangle’,bboxOut,’ShapeColor’,’black’);
iannotate = insertObjectAnnotation(vidframe,"rectangle",bboxOut,’banana’,TextBoxOpacity=0.9,FontSize=18);
%paly in video player
vidPlayer = vision.DeployableVideoPlayer;
%step(vidPlayer,ishape);
step(vidPlayer,iannotate);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
%release(ishape) computer vision, image processing MATLAB Answers — New Questions
Event-triggered control for 2D in Roesser model
Hi everyone, please help me write the matlab code to describe the solution trajectories and event-triggered instants for the 2D systems with event-triggered control as follow. Thank you for your help!Hi everyone, please help me write the matlab code to describe the solution trajectories and event-triggered instants for the 2D systems with event-triggered control as follow. Thank you for your help! Hi everyone, please help me write the matlab code to describe the solution trajectories and event-triggered instants for the 2D systems with event-triggered control as follow. Thank you for your help! event-triggered control MATLAB Answers — New Questions
Simulink Model to transfer function via simulink and Matlab
hi everyone,
in the picture i uploaded you can see my closed loop model for a dynamic system.
im trying to get the transfer function between the input signal Va to the output signal Phi , while considering all the feedbacks.
when i do it by the model linearizer app or the control system designer i get strange bode plots and wrong transfer functions.
so i would like you to help me understand how can i do it correctly plese.
the seconed question is how can i get the same closed loop transfer function on simulink script by using feedback command.
thank you!hi everyone,
in the picture i uploaded you can see my closed loop model for a dynamic system.
im trying to get the transfer function between the input signal Va to the output signal Phi , while considering all the feedbacks.
when i do it by the model linearizer app or the control system designer i get strange bode plots and wrong transfer functions.
so i would like you to help me understand how can i do it correctly plese.
the seconed question is how can i get the same closed loop transfer function on simulink script by using feedback command.
thank you! hi everyone,
in the picture i uploaded you can see my closed loop model for a dynamic system.
im trying to get the transfer function between the input signal Va to the output signal Phi , while considering all the feedbacks.
when i do it by the model linearizer app or the control system designer i get strange bode plots and wrong transfer functions.
so i would like you to help me understand how can i do it correctly plese.
the seconed question is how can i get the same closed loop transfer function on simulink script by using feedback command.
thank you! simulink, matlab, control, control_system, model MATLAB Answers — New Questions
why in example”Architectural 112G PAM4 ADC-Based SerDes Model”,symbol time is set to 18.8235e-12,which is 106GHz
Post Content Post Content symbol time, 112g MATLAB Answers — New Questions
The equation of the curve at the intersection of the two 3D surface, One is a cylinder.
There is a cylinder centered at (0,0) and extending in the direction of the z-axis. Then there is a 3D surface represented by some z=f(x,y). I want to express the equation of the intersection of these two by z=g(x,y). Please show me how to do this calculation.
I executed the following code, but I do not know what the calculated value indicates. I would appreciate it if you could tell me this as well.
———————————-
% シンボリック変数の定義
syms x y z
% 円筒と平面の方程式
r = 5; % 円筒の半径
cylinder_eq = x^2 + y^2 == r^2; % 円筒の方程式
plane_eq = z == x * y + 3; % 平面の方程式
z_range = z < 1000;
% 連立方程式を解く
sol = solve([cylinder_eq, plane_eq, z_range], [x, y, z]);
% 解の表示
disp(sol)
disp(sol.x)
disp(sol.y)
disp(sol.z)
———————————-
x: [7×1 sym]
y: [7×1 sym]
z: [7×1 sym]
(25/2 – 589^(1/2)/2)^(3/2)/3 – (25*(25/2 – 589^(1/2)/2)^(1/2))/3
(589^(1/2)/2 + 25/2)^(3/2)/3 – (25*(589^(1/2)/2 + 25/2)^(1/2))/3
0
0
0
(25*(25/2 – 589^(1/2)/2)^(1/2))/3 – (25/2 – 589^(1/2)/2)^(3/2)/3
(25*(589^(1/2)/2 + 25/2)^(1/2))/3 – (589^(1/2)/2 + 25/2)^(3/2)/3
(25/2 – 589^(1/2)/2)^(1/2)
(589^(1/2)/2 + 25/2)^(1/2)
0
-5
5
-(25/2 – 589^(1/2)/2)^(1/2)
-(589^(1/2)/2 + 25/2)^(1/2)
0
0
3
3
3
0
0There is a cylinder centered at (0,0) and extending in the direction of the z-axis. Then there is a 3D surface represented by some z=f(x,y). I want to express the equation of the intersection of these two by z=g(x,y). Please show me how to do this calculation.
I executed the following code, but I do not know what the calculated value indicates. I would appreciate it if you could tell me this as well.
———————————-
% シンボリック変数の定義
syms x y z
% 円筒と平面の方程式
r = 5; % 円筒の半径
cylinder_eq = x^2 + y^2 == r^2; % 円筒の方程式
plane_eq = z == x * y + 3; % 平面の方程式
z_range = z < 1000;
% 連立方程式を解く
sol = solve([cylinder_eq, plane_eq, z_range], [x, y, z]);
% 解の表示
disp(sol)
disp(sol.x)
disp(sol.y)
disp(sol.z)
———————————-
x: [7×1 sym]
y: [7×1 sym]
z: [7×1 sym]
(25/2 – 589^(1/2)/2)^(3/2)/3 – (25*(25/2 – 589^(1/2)/2)^(1/2))/3
(589^(1/2)/2 + 25/2)^(3/2)/3 – (25*(589^(1/2)/2 + 25/2)^(1/2))/3
0
0
0
(25*(25/2 – 589^(1/2)/2)^(1/2))/3 – (25/2 – 589^(1/2)/2)^(3/2)/3
(25*(589^(1/2)/2 + 25/2)^(1/2))/3 – (589^(1/2)/2 + 25/2)^(3/2)/3
(25/2 – 589^(1/2)/2)^(1/2)
(589^(1/2)/2 + 25/2)^(1/2)
0
-5
5
-(25/2 – 589^(1/2)/2)^(1/2)
-(589^(1/2)/2 + 25/2)^(1/2)
0
0
3
3
3
0
0 There is a cylinder centered at (0,0) and extending in the direction of the z-axis. Then there is a 3D surface represented by some z=f(x,y). I want to express the equation of the intersection of these two by z=g(x,y). Please show me how to do this calculation.
I executed the following code, but I do not know what the calculated value indicates. I would appreciate it if you could tell me this as well.
———————————-
% シンボリック変数の定義
syms x y z
% 円筒と平面の方程式
r = 5; % 円筒の半径
cylinder_eq = x^2 + y^2 == r^2; % 円筒の方程式
plane_eq = z == x * y + 3; % 平面の方程式
z_range = z < 1000;
% 連立方程式を解く
sol = solve([cylinder_eq, plane_eq, z_range], [x, y, z]);
% 解の表示
disp(sol)
disp(sol.x)
disp(sol.y)
disp(sol.z)
———————————-
x: [7×1 sym]
y: [7×1 sym]
z: [7×1 sym]
(25/2 – 589^(1/2)/2)^(3/2)/3 – (25*(25/2 – 589^(1/2)/2)^(1/2))/3
(589^(1/2)/2 + 25/2)^(3/2)/3 – (25*(589^(1/2)/2 + 25/2)^(1/2))/3
0
0
0
(25*(25/2 – 589^(1/2)/2)^(1/2))/3 – (25/2 – 589^(1/2)/2)^(3/2)/3
(25*(589^(1/2)/2 + 25/2)^(1/2))/3 – (589^(1/2)/2 + 25/2)^(3/2)/3
(25/2 – 589^(1/2)/2)^(1/2)
(589^(1/2)/2 + 25/2)^(1/2)
0
-5
5
-(25/2 – 589^(1/2)/2)^(1/2)
-(589^(1/2)/2 + 25/2)^(1/2)
0
0
3
3
3
0
0 3d, cylinder, intersection, equation MATLAB Answers — New Questions
How to change the color of shapefile in pcolor plot
I have a pcolor global plot over which i have imposed a worldcoastal shapefile. However, i wish to change the default color from blue to black.I have a pcolor global plot over which i have imposed a worldcoastal shapefile. However, i wish to change the default color from blue to black. I have a pcolor global plot over which i have imposed a worldcoastal shapefile. However, i wish to change the default color from blue to black. shapefile, pcolor, edgecolor, facecolor MATLAB Answers — New Questions
Training a deep neural network with a database as input
After converting my data into a combined datastore, I tried training a deep neural network with the architecture shown below but the error " Error forming mini-batch for network input "sequence_prop". Data interpreted with format "CBT". To specify a different format, use the InputDataFormats option.
Error in netPaperv4 net = trainnet(dsTrain, net, "mse", options);
Caused by:
Batch dimension of datastore must match the format batch dimension (2)." occurred.
Here a datastore preview: 1×2 cell array
{[-0.2964 -0.2723 0 0.3049 0.1613 -0.9312]} {[2.2746]}
I want to combine three different sequence inputs (the goal is time series forecasting, not image classification: my inputs are all time-depending sequences) : two of size 1 and the other of size 4 to predict a single output (size 1).
Can anyone help me solve this? I can provide code if needed.After converting my data into a combined datastore, I tried training a deep neural network with the architecture shown below but the error " Error forming mini-batch for network input "sequence_prop". Data interpreted with format "CBT". To specify a different format, use the InputDataFormats option.
Error in netPaperv4 net = trainnet(dsTrain, net, "mse", options);
Caused by:
Batch dimension of datastore must match the format batch dimension (2)." occurred.
Here a datastore preview: 1×2 cell array
{[-0.2964 -0.2723 0 0.3049 0.1613 -0.9312]} {[2.2746]}
I want to combine three different sequence inputs (the goal is time series forecasting, not image classification: my inputs are all time-depending sequences) : two of size 1 and the other of size 4 to predict a single output (size 1).
Can anyone help me solve this? I can provide code if needed. After converting my data into a combined datastore, I tried training a deep neural network with the architecture shown below but the error " Error forming mini-batch for network input "sequence_prop". Data interpreted with format "CBT". To specify a different format, use the InputDataFormats option.
Error in netPaperv4 net = trainnet(dsTrain, net, "mse", options);
Caused by:
Batch dimension of datastore must match the format batch dimension (2)." occurred.
Here a datastore preview: 1×2 cell array
{[-0.2964 -0.2723 0 0.3049 0.1613 -0.9312]} {[2.2746]}
I want to combine three different sequence inputs (the goal is time series forecasting, not image classification: my inputs are all time-depending sequences) : two of size 1 and the other of size 4 to predict a single output (size 1).
Can anyone help me solve this? I can provide code if needed. deep neural network, deep learning, time series forecasting, database, time series MATLAB Answers — New Questions
Output Error of ultrasonicDetectionGenerator in Simulink
The measurement error that occurred previously is no longer happening.
If no input is provided to the Scenario Reader, no errors occur.
However, when I start providing values through parkEgo in the Scenario, the ultrasonicDetectionGenerator fails to produce any output and continuously encounters errors.
The simulation does not terminate due to the error, but it remains stuck without producing any output, and when I press ctrl+c in the Matlab command window, it always shows an error in the Implement of ultrasonicDetectionGenerator.
https://kr.mathworks.com/matlabcentral/answers/2137952-measurement-error-of-ultrasonic-sensor-in-driving-scenario-designer/?s_tid=ans_lp_feed_leaf
Due to the above issue, I am currently using the prerelease version 2024b.
시뮬레이션 중에 오류가 발생하여 시뮬레이션이 종료되었습니다
원인:
‘ultrasonicDetectionGenerator’의 ‘stepImpl’ 메서드를 호출할 때 MATLAB System 블록 ‘AIV_robot/Environment/Simulation/Ultrasonic Sensor Processing/Ultrasonic5’에서 오류가 발생했습니다.
프로그램 중단(Ctrl+C)이 감지되었습니다.
An error occurred during the simulation, causing it to terminate.
Cause:
An error occurred in the MATLAB System block ‘AIV_robot/Environment/Simulation/Ultrasonic Sensor Processing/Ultrasonic5’ while calling the ‘stepImpl’ method of ‘ultrasonicDetectionGenerator’.
Program interruption (Ctrl+C) was detected.The measurement error that occurred previously is no longer happening.
If no input is provided to the Scenario Reader, no errors occur.
However, when I start providing values through parkEgo in the Scenario, the ultrasonicDetectionGenerator fails to produce any output and continuously encounters errors.
The simulation does not terminate due to the error, but it remains stuck without producing any output, and when I press ctrl+c in the Matlab command window, it always shows an error in the Implement of ultrasonicDetectionGenerator.
https://kr.mathworks.com/matlabcentral/answers/2137952-measurement-error-of-ultrasonic-sensor-in-driving-scenario-designer/?s_tid=ans_lp_feed_leaf
Due to the above issue, I am currently using the prerelease version 2024b.
시뮬레이션 중에 오류가 발생하여 시뮬레이션이 종료되었습니다
원인:
‘ultrasonicDetectionGenerator’의 ‘stepImpl’ 메서드를 호출할 때 MATLAB System 블록 ‘AIV_robot/Environment/Simulation/Ultrasonic Sensor Processing/Ultrasonic5’에서 오류가 발생했습니다.
프로그램 중단(Ctrl+C)이 감지되었습니다.
An error occurred during the simulation, causing it to terminate.
Cause:
An error occurred in the MATLAB System block ‘AIV_robot/Environment/Simulation/Ultrasonic Sensor Processing/Ultrasonic5’ while calling the ‘stepImpl’ method of ‘ultrasonicDetectionGenerator’.
Program interruption (Ctrl+C) was detected. The measurement error that occurred previously is no longer happening.
If no input is provided to the Scenario Reader, no errors occur.
However, when I start providing values through parkEgo in the Scenario, the ultrasonicDetectionGenerator fails to produce any output and continuously encounters errors.
The simulation does not terminate due to the error, but it remains stuck without producing any output, and when I press ctrl+c in the Matlab command window, it always shows an error in the Implement of ultrasonicDetectionGenerator.
https://kr.mathworks.com/matlabcentral/answers/2137952-measurement-error-of-ultrasonic-sensor-in-driving-scenario-designer/?s_tid=ans_lp_feed_leaf
Due to the above issue, I am currently using the prerelease version 2024b.
시뮬레이션 중에 오류가 발생하여 시뮬레이션이 종료되었습니다
원인:
‘ultrasonicDetectionGenerator’의 ‘stepImpl’ 메서드를 호출할 때 MATLAB System 블록 ‘AIV_robot/Environment/Simulation/Ultrasonic Sensor Processing/Ultrasonic5’에서 오류가 발생했습니다.
프로그램 중단(Ctrl+C)이 감지되었습니다.
An error occurred during the simulation, causing it to terminate.
Cause:
An error occurred in the MATLAB System block ‘AIV_robot/Environment/Simulation/Ultrasonic Sensor Processing/Ultrasonic5’ while calling the ‘stepImpl’ method of ‘ultrasonicDetectionGenerator’.
Program interruption (Ctrl+C) was detected. driving scenario designer, ultrasonicdetectiongenerator, scenarioreader, simulink, matlab MATLAB Answers — New Questions
How can I write a script to replace a specific integer value in my table, with the average of the data above and below that integer in the table
Basically, I am trying to write a script to be able to find the value 999 in my table, and add the nearest possible values above and below the 999.
For example, if 999 were a value in row 10, column 4, I would want to add 12+18, then divide by 2, and then replace that 999. If 12, 16, 18 were all set to 999, I would want to add 10 and 22, then divide by 2. Then replace 12, 16, 18 all with 16.
Complete beginner to matlab, so I don’t understand the syntax of how I would do this. Is this even possible with any sort of loop?Basically, I am trying to write a script to be able to find the value 999 in my table, and add the nearest possible values above and below the 999.
For example, if 999 were a value in row 10, column 4, I would want to add 12+18, then divide by 2, and then replace that 999. If 12, 16, 18 were all set to 999, I would want to add 10 and 22, then divide by 2. Then replace 12, 16, 18 all with 16.
Complete beginner to matlab, so I don’t understand the syntax of how I would do this. Is this even possible with any sort of loop? Basically, I am trying to write a script to be able to find the value 999 in my table, and add the nearest possible values above and below the 999.
For example, if 999 were a value in row 10, column 4, I would want to add 12+18, then divide by 2, and then replace that 999. If 12, 16, 18 were all set to 999, I would want to add 10 and 22, then divide by 2. Then replace 12, 16, 18 all with 16.
Complete beginner to matlab, so I don’t understand the syntax of how I would do this. Is this even possible with any sort of loop? table, script MATLAB Answers — New Questions
I have a txt file which has data in netcdf format. How to read it?
so i downloaded imerg data for 90 days from GES DISC. the whole file got downloaded in txt but the data in it looks like this
https://data.gesdisc.earthdata.nasa.gov/data/GPM_L3/GPM_3IMERGDF.07/2023/06/3B-DAY.MS.MRG.3IMERG.20230618-S000000-E235959.V07B.nc4. i have 90 of these. how can i open this in matalb. i want to plot a graph like this. how can i do it.so i downloaded imerg data for 90 days from GES DISC. the whole file got downloaded in txt but the data in it looks like this
https://data.gesdisc.earthdata.nasa.gov/data/GPM_L3/GPM_3IMERGDF.07/2023/06/3B-DAY.MS.MRG.3IMERG.20230618-S000000-E235959.V07B.nc4. i have 90 of these. how can i open this in matalb. i want to plot a graph like this. how can i do it. so i downloaded imerg data for 90 days from GES DISC. the whole file got downloaded in txt but the data in it looks like this
https://data.gesdisc.earthdata.nasa.gov/data/GPM_L3/GPM_3IMERGDF.07/2023/06/3B-DAY.MS.MRG.3IMERG.20230618-S000000-E235959.V07B.nc4. i have 90 of these. how can i open this in matalb. i want to plot a graph like this. how can i do it. txt file, plot, geoplot MATLAB Answers — New Questions
How to read a raw image URL directly from a GitHub public repository via the imread function?
As far as I know, imread built-in function supports to read the image address file of a URL directly, but for a certain URL image address in public repository on Github, I can’t read it by MATLAB, instead I can read it by using linux command `wget`, may I know how to read the image correctly by imread function?
Example:
imgPath = "https://github.com/Experience-Monks/360-image-viewer/blob/master/demo/pano_2048.jpg";
img = imread(imgPath);As far as I know, imread built-in function supports to read the image address file of a URL directly, but for a certain URL image address in public repository on Github, I can’t read it by MATLAB, instead I can read it by using linux command `wget`, may I know how to read the image correctly by imread function?
Example:
imgPath = "https://github.com/Experience-Monks/360-image-viewer/blob/master/demo/pano_2048.jpg";
img = imread(imgPath); As far as I know, imread built-in function supports to read the image address file of a URL directly, but for a certain URL image address in public repository on Github, I can’t read it by MATLAB, instead I can read it by using linux command `wget`, may I know how to read the image correctly by imread function?
Example:
imgPath = "https://github.com/Experience-Monks/360-image-viewer/blob/master/demo/pano_2048.jpg";
img = imread(imgPath); imread, github MATLAB Answers — New Questions
How can I properly create an standalone APP which includes python .py scripts?
Hello, I am facing difficulties to properly compile an standalone Matlab APP which includes python .py scripts. It works fine inside Matlab 2022a environment, however the standalone APP (from APP Designer) does not work, it sounds a beep and the .py scripts don´t run properly. Is there a guide or educational material that I could follow to make that in the proper way?
Is there something that I should include in the Startup FCN ?
Thanks,Hello, I am facing difficulties to properly compile an standalone Matlab APP which includes python .py scripts. It works fine inside Matlab 2022a environment, however the standalone APP (from APP Designer) does not work, it sounds a beep and the .py scripts don´t run properly. Is there a guide or educational material that I could follow to make that in the proper way?
Is there something that I should include in the Startup FCN ?
Thanks, Hello, I am facing difficulties to properly compile an standalone Matlab APP which includes python .py scripts. It works fine inside Matlab 2022a environment, however the standalone APP (from APP Designer) does not work, it sounds a beep and the .py scripts don´t run properly. Is there a guide or educational material that I could follow to make that in the proper way?
Is there something that I should include in the Startup FCN ?
Thanks, matlab compiler, app designer, appdesigner, python MATLAB Answers — New Questions