Tag Archives: matlab
Problem with updateLimitsAndDirection function
Good afternoon,
I’m using MATLAB’s Visual SLAM with RGB-D Camera example (https://uk.mathworks.com/help/vision/ug/visual-slam-with-an-rgbd-camera.html), and I got this error message:
"Error using worldpointset/updateLimitsAndDirection
Invalid location for world point 1. It coincides with one of the views that observes the world point."
When I am exercuting this line of code:
mapPointSet = updateLimitsAndDirection(mapPointSet, rgbdMapPointsIdx, vSetKeyFrames.Views);
In:
% Create an empty imageviewset object to store key frames
vSetKeyFrames = imageviewset;
% Create an empty worldpointset object to store 3-D map points
mapPointSet = worldpointset;
% Add the first key frame
vSetKeyFrames = addView(vSetKeyFrames, currKeyFrameId, initialPose, Points=currPoints,…
Features=currFeatures.Features);
% Add 3-D map points
[mapPointSet, rgbdMapPointsIdx] = addWorldPoints(mapPointSet, xyzPoints);
% Add observations of the map points
mapPointSet = addCorrespondences(mapPointSet, currKeyFrameId, rgbdMapPointsIdx, validIndex);
% Update view direction and depth
mapPointSet = updateLimitsAndDirection(mapPointSet, rgbdMapPointsIdx, vSetKeyFrames.Views);
In the example code, I’ve just modified the download and browse part of the input image sequence.
The code I’ve added is as follows:
% Select the synchronized image data
Path_RGB = ‘C:Documents2.5RGB cameraImage for bad of wordsRGB’;
Path_Grey = ‘C:Documents2.5RGB cameraImage for bad of wordsDepth’;
imdsColor = imageDatastore(Path_RGB);
imdsDepth = imageDatastore(Path_Grey);
% imdsColor = subset(imdsColor, indexPairs(:, 1));
% imdsDepth = subset(imdsDepth, indexPairs(:, 2));
% Inspect the first RGB-D image
currFrameIdx = 1;
currIcolor = readimage(imdsColor, currFrameIdx);
currIdepth = readimage(imdsDepth, currFrameIdx);
currIdepth = rgb2gray(currIdepth);
[rows, colums] = size(currIdepth);
currIcolor = imresize(currIcolor, [rows colums]);
imshowpair(currIcolor, currIdepth, "montage");
I am using MATLAB R2023b, and I’ve done some research on the Internet, but I haven’t found a solution. Can you help me?
Thank you very much.Good afternoon,
I’m using MATLAB’s Visual SLAM with RGB-D Camera example (https://uk.mathworks.com/help/vision/ug/visual-slam-with-an-rgbd-camera.html), and I got this error message:
"Error using worldpointset/updateLimitsAndDirection
Invalid location for world point 1. It coincides with one of the views that observes the world point."
When I am exercuting this line of code:
mapPointSet = updateLimitsAndDirection(mapPointSet, rgbdMapPointsIdx, vSetKeyFrames.Views);
In:
% Create an empty imageviewset object to store key frames
vSetKeyFrames = imageviewset;
% Create an empty worldpointset object to store 3-D map points
mapPointSet = worldpointset;
% Add the first key frame
vSetKeyFrames = addView(vSetKeyFrames, currKeyFrameId, initialPose, Points=currPoints,…
Features=currFeatures.Features);
% Add 3-D map points
[mapPointSet, rgbdMapPointsIdx] = addWorldPoints(mapPointSet, xyzPoints);
% Add observations of the map points
mapPointSet = addCorrespondences(mapPointSet, currKeyFrameId, rgbdMapPointsIdx, validIndex);
% Update view direction and depth
mapPointSet = updateLimitsAndDirection(mapPointSet, rgbdMapPointsIdx, vSetKeyFrames.Views);
In the example code, I’ve just modified the download and browse part of the input image sequence.
The code I’ve added is as follows:
% Select the synchronized image data
Path_RGB = ‘C:Documents2.5RGB cameraImage for bad of wordsRGB’;
Path_Grey = ‘C:Documents2.5RGB cameraImage for bad of wordsDepth’;
imdsColor = imageDatastore(Path_RGB);
imdsDepth = imageDatastore(Path_Grey);
% imdsColor = subset(imdsColor, indexPairs(:, 1));
% imdsDepth = subset(imdsDepth, indexPairs(:, 2));
% Inspect the first RGB-D image
currFrameIdx = 1;
currIcolor = readimage(imdsColor, currFrameIdx);
currIdepth = readimage(imdsDepth, currFrameIdx);
currIdepth = rgb2gray(currIdepth);
[rows, colums] = size(currIdepth);
currIcolor = imresize(currIcolor, [rows colums]);
imshowpair(currIcolor, currIdepth, "montage");
I am using MATLAB R2023b, and I’ve done some research on the Internet, but I haven’t found a solution. Can you help me?
Thank you very much. Good afternoon,
I’m using MATLAB’s Visual SLAM with RGB-D Camera example (https://uk.mathworks.com/help/vision/ug/visual-slam-with-an-rgbd-camera.html), and I got this error message:
"Error using worldpointset/updateLimitsAndDirection
Invalid location for world point 1. It coincides with one of the views that observes the world point."
When I am exercuting this line of code:
mapPointSet = updateLimitsAndDirection(mapPointSet, rgbdMapPointsIdx, vSetKeyFrames.Views);
In:
% Create an empty imageviewset object to store key frames
vSetKeyFrames = imageviewset;
% Create an empty worldpointset object to store 3-D map points
mapPointSet = worldpointset;
% Add the first key frame
vSetKeyFrames = addView(vSetKeyFrames, currKeyFrameId, initialPose, Points=currPoints,…
Features=currFeatures.Features);
% Add 3-D map points
[mapPointSet, rgbdMapPointsIdx] = addWorldPoints(mapPointSet, xyzPoints);
% Add observations of the map points
mapPointSet = addCorrespondences(mapPointSet, currKeyFrameId, rgbdMapPointsIdx, validIndex);
% Update view direction and depth
mapPointSet = updateLimitsAndDirection(mapPointSet, rgbdMapPointsIdx, vSetKeyFrames.Views);
In the example code, I’ve just modified the download and browse part of the input image sequence.
The code I’ve added is as follows:
% Select the synchronized image data
Path_RGB = ‘C:Documents2.5RGB cameraImage for bad of wordsRGB’;
Path_Grey = ‘C:Documents2.5RGB cameraImage for bad of wordsDepth’;
imdsColor = imageDatastore(Path_RGB);
imdsDepth = imageDatastore(Path_Grey);
% imdsColor = subset(imdsColor, indexPairs(:, 1));
% imdsDepth = subset(imdsDepth, indexPairs(:, 2));
% Inspect the first RGB-D image
currFrameIdx = 1;
currIcolor = readimage(imdsColor, currFrameIdx);
currIdepth = readimage(imdsDepth, currFrameIdx);
currIdepth = rgb2gray(currIdepth);
[rows, colums] = size(currIdepth);
currIcolor = imresize(currIcolor, [rows colums]);
imshowpair(currIcolor, currIdepth, "montage");
I am using MATLAB R2023b, and I’ve done some research on the Internet, but I haven’t found a solution. Can you help me?
Thank you very much. rgb-d camera, updatelimitsanddirection, computer vision toolbox MATLAB Answers — New Questions
Problems with legend in R2016b
Why can I no longer add a plot with a legend in R2016b same way it used to be in previews versions?
During the migration to R2016b or R2017a, the script show some problems with legend function in the plot.
An example is a simple line after a plot:
legend(‘Curve1′,’Curve2’,1);
While it used to work fine prior to R2016b, we see the following response :
Error using legend>process_inputs (line 582)
Invalid argument. Type ‘help legend’ for more information.
Error in legend>make_legend (line 340)
[autoupdate,orient,location,position,children,listen,strings,propargs] = process_inputs(ha,argin); %#ok
Error in legend (line 294)
make_legend(ha,args(arg:end),version);
Error in Script_plot (line 274)
legend(‘Curve1′,’Curve2’,1);Why can I no longer add a plot with a legend in R2016b same way it used to be in previews versions?
During the migration to R2016b or R2017a, the script show some problems with legend function in the plot.
An example is a simple line after a plot:
legend(‘Curve1′,’Curve2’,1);
While it used to work fine prior to R2016b, we see the following response :
Error using legend>process_inputs (line 582)
Invalid argument. Type ‘help legend’ for more information.
Error in legend>make_legend (line 340)
[autoupdate,orient,location,position,children,listen,strings,propargs] = process_inputs(ha,argin); %#ok
Error in legend (line 294)
make_legend(ha,args(arg:end),version);
Error in Script_plot (line 274)
legend(‘Curve1′,’Curve2’,1); Why can I no longer add a plot with a legend in R2016b same way it used to be in previews versions?
During the migration to R2016b or R2017a, the script show some problems with legend function in the plot.
An example is a simple line after a plot:
legend(‘Curve1′,’Curve2’,1);
While it used to work fine prior to R2016b, we see the following response :
Error using legend>process_inputs (line 582)
Invalid argument. Type ‘help legend’ for more information.
Error in legend>make_legend (line 340)
[autoupdate,orient,location,position,children,listen,strings,propargs] = process_inputs(ha,argin); %#ok
Error in legend (line 294)
make_legend(ha,args(arg:end),version);
Error in Script_plot (line 274)
legend(‘Curve1′,’Curve2’,1); legend, plot MATLAB Answers — New Questions
How to perform matrix math
Hello all, I currently have a code to look at delta distances in a .csv file and ouput a new csv files with these a summation of these distances for each of the three columns. This code looks at three columns in a .csv files, subtracts the second row from the first row and continues this calculation down all the rows. I have had the chance to look at some of this distance data and it looks good but I need to tweak my calculation. Where I have S = sum(abs(diff(M(:,2:4),1,1)),1).
I would like to continue this method of subtracting the second line from the first and moving down. But I need an intermediate step (or 2) where the values are subtracted values are squared. The that row of values would be added up and the sqrt of that would be taken.That end value would be added to the end values of that operation performed down the rows.
I have attached an image that explains this clearer (I hope). Its a way of doing the distance formula. I just need to loop it for 500 x y and z coordinates. I will also attach an example file of the data in .csv form. Thank you, any help is much appreciated!
clc
% appropriate dir() call that returns info
% about the files you want to process:
fn = dir(‘C:UserslucasarsenithDesktopData/*.csv’); % this call returns info about .csv files in the current directory;
% you may need to modify it to work for your file locations
% (see dir documentation)
% number of files:
N_files = numel(fn);
% pre-allocate results matrix (one row per file, 3 columns):
results = zeros(N_files,3);
% read and process each file:
for ii = 1:N_files
% read the file starting from line 10:
M = readmatrix(fullfile(fn(ii).folder,fn(ii).name));
% process columns 2-4 of the file’s data:
S = sum(abs(diff(M(:,2:4),1,1)),1);
% store the result:
results(ii,:) = S;
end
% write the results file (can be located anywhere):
writematrix(results,’C:UserslucasarsenithDesktopPlot.csv’)Hello all, I currently have a code to look at delta distances in a .csv file and ouput a new csv files with these a summation of these distances for each of the three columns. This code looks at three columns in a .csv files, subtracts the second row from the first row and continues this calculation down all the rows. I have had the chance to look at some of this distance data and it looks good but I need to tweak my calculation. Where I have S = sum(abs(diff(M(:,2:4),1,1)),1).
I would like to continue this method of subtracting the second line from the first and moving down. But I need an intermediate step (or 2) where the values are subtracted values are squared. The that row of values would be added up and the sqrt of that would be taken.That end value would be added to the end values of that operation performed down the rows.
I have attached an image that explains this clearer (I hope). Its a way of doing the distance formula. I just need to loop it for 500 x y and z coordinates. I will also attach an example file of the data in .csv form. Thank you, any help is much appreciated!
clc
% appropriate dir() call that returns info
% about the files you want to process:
fn = dir(‘C:UserslucasarsenithDesktopData/*.csv’); % this call returns info about .csv files in the current directory;
% you may need to modify it to work for your file locations
% (see dir documentation)
% number of files:
N_files = numel(fn);
% pre-allocate results matrix (one row per file, 3 columns):
results = zeros(N_files,3);
% read and process each file:
for ii = 1:N_files
% read the file starting from line 10:
M = readmatrix(fullfile(fn(ii).folder,fn(ii).name));
% process columns 2-4 of the file’s data:
S = sum(abs(diff(M(:,2:4),1,1)),1);
% store the result:
results(ii,:) = S;
end
% write the results file (can be located anywhere):
writematrix(results,’C:UserslucasarsenithDesktopPlot.csv’) Hello all, I currently have a code to look at delta distances in a .csv file and ouput a new csv files with these a summation of these distances for each of the three columns. This code looks at three columns in a .csv files, subtracts the second row from the first row and continues this calculation down all the rows. I have had the chance to look at some of this distance data and it looks good but I need to tweak my calculation. Where I have S = sum(abs(diff(M(:,2:4),1,1)),1).
I would like to continue this method of subtracting the second line from the first and moving down. But I need an intermediate step (or 2) where the values are subtracted values are squared. The that row of values would be added up and the sqrt of that would be taken.That end value would be added to the end values of that operation performed down the rows.
I have attached an image that explains this clearer (I hope). Its a way of doing the distance formula. I just need to loop it for 500 x y and z coordinates. I will also attach an example file of the data in .csv form. Thank you, any help is much appreciated!
clc
% appropriate dir() call that returns info
% about the files you want to process:
fn = dir(‘C:UserslucasarsenithDesktopData/*.csv’); % this call returns info about .csv files in the current directory;
% you may need to modify it to work for your file locations
% (see dir documentation)
% number of files:
N_files = numel(fn);
% pre-allocate results matrix (one row per file, 3 columns):
results = zeros(N_files,3);
% read and process each file:
for ii = 1:N_files
% read the file starting from line 10:
M = readmatrix(fullfile(fn(ii).folder,fn(ii).name));
% process columns 2-4 of the file’s data:
S = sum(abs(diff(M(:,2:4),1,1)),1);
% store the result:
results(ii,:) = S;
end
% write the results file (can be located anywhere):
writematrix(results,’C:UserslucasarsenithDesktopPlot.csv’) matrix, matrices, mathematics MATLAB Answers — New Questions
Pick out rows from an array where the 1st column is closest to a multiple of a number
Hello, Im trying to downsample a 100k lines of excel and want to pick out only those rows where the column 1 values are closest to multiples of a number, say 50. So in the pic below, just the green highlighted rows.
I’ve thought about using mod but this doesn’t work:
%For example if I choose these numbers (and consider just a column vector)
n=[1;5;7;9;12;15;29;33;39]
and want to pick out those numbers closest to multiples of 10
mod(n,10)
ans =
1
5
7
9
2
5
9
3
9
If I sort these and pick out the lowest ones, the value of 29 & 39 wouldn’t be picked out.
I also considered some kind of interp, but I need to pick out the actual discrete value from the table below not an interpolated value. Normally I show my arttempt, but Im actually stuck here in where to actually start with this.Hello, Im trying to downsample a 100k lines of excel and want to pick out only those rows where the column 1 values are closest to multiples of a number, say 50. So in the pic below, just the green highlighted rows.
I’ve thought about using mod but this doesn’t work:
%For example if I choose these numbers (and consider just a column vector)
n=[1;5;7;9;12;15;29;33;39]
and want to pick out those numbers closest to multiples of 10
mod(n,10)
ans =
1
5
7
9
2
5
9
3
9
If I sort these and pick out the lowest ones, the value of 29 & 39 wouldn’t be picked out.
I also considered some kind of interp, but I need to pick out the actual discrete value from the table below not an interpolated value. Normally I show my arttempt, but Im actually stuck here in where to actually start with this. Hello, Im trying to downsample a 100k lines of excel and want to pick out only those rows where the column 1 values are closest to multiples of a number, say 50. So in the pic below, just the green highlighted rows.
I’ve thought about using mod but this doesn’t work:
%For example if I choose these numbers (and consider just a column vector)
n=[1;5;7;9;12;15;29;33;39]
and want to pick out those numbers closest to multiples of 10
mod(n,10)
ans =
1
5
7
9
2
5
9
3
9
If I sort these and pick out the lowest ones, the value of 29 & 39 wouldn’t be picked out.
I also considered some kind of interp, but I need to pick out the actual discrete value from the table below not an interpolated value. Normally I show my arttempt, but Im actually stuck here in where to actually start with this. array, mod MATLAB Answers — New Questions
I am trying to convert the date data from the CSV file to datetime, but it shows error, how do I fix this
dates=string(raw.textdata(2:end,1));%import the string dates from the data
dates=datetime(dates,’InputFormat’,’dd/MM/yy’); %convert date strings to date time format
%monthly vectors
m=unique(month(dates));%Get unique months form the data set
m_sum_Production=zeros(length(m),1);%initial monthly sum of Production
m_sum_T_Consumption=zeros(length(m),1);%initial monthly sum of Total Consumption
m_sum_O_Consumption=zeros(length(m),1);%initial monthly sum of Own Consumption
for i =1:length(m)
current_months=month(dates)==m(i); %checks each date to see if its month matches the current month
m_sum_Production(i) = sum(Production(current_months));%monthly sum of Production
m_sum_T_Consumption(i) = sum(T_Consumption(current_months));%monthly sum of Total Consumption
m_sum_O_Consumption(i) = sum(O_Consumption(current_months));%monthly sum of Own Consumption
end
code above
dates =
1505×1 string array
"06-Apr-20"
"07-Apr-20"
"08-Apr-20"
"09-Apr-20"
"10-Apr-20"
"11-Apr-20"
"12-Apr-20"
"13-Apr-20"
"14-Apr-20"
"15-Apr-20"
"16-Apr-20"
"17-Apr-20"
"18-Apr-20"
"19-Apr-20"
"20-Apr-20"
"21-Apr-20"
"22-Apr-20"
"23-Apr-20"
"24-Apr-20"
"25-Apr-20"
"26-Apr-20"
"27-Apr-20"
"28-Apr-20"
"29-Apr-20"
"30-Apr-20"
"01-May-20"
"02-May-20"
"03-May-20"
"04-May-20"
"05-May-20"
"06-May-20"
error encounter below
Error using datetime (line 667)
Unable to convert the text to datetime using the format ‘dd/MM/yy’.
Error in Q3 (line 13)
dates=datetime(dates,’InputFormat’,’dd/MM/yy’); %convert date strings to date time formatdates=string(raw.textdata(2:end,1));%import the string dates from the data
dates=datetime(dates,’InputFormat’,’dd/MM/yy’); %convert date strings to date time format
%monthly vectors
m=unique(month(dates));%Get unique months form the data set
m_sum_Production=zeros(length(m),1);%initial monthly sum of Production
m_sum_T_Consumption=zeros(length(m),1);%initial monthly sum of Total Consumption
m_sum_O_Consumption=zeros(length(m),1);%initial monthly sum of Own Consumption
for i =1:length(m)
current_months=month(dates)==m(i); %checks each date to see if its month matches the current month
m_sum_Production(i) = sum(Production(current_months));%monthly sum of Production
m_sum_T_Consumption(i) = sum(T_Consumption(current_months));%monthly sum of Total Consumption
m_sum_O_Consumption(i) = sum(O_Consumption(current_months));%monthly sum of Own Consumption
end
code above
dates =
1505×1 string array
"06-Apr-20"
"07-Apr-20"
"08-Apr-20"
"09-Apr-20"
"10-Apr-20"
"11-Apr-20"
"12-Apr-20"
"13-Apr-20"
"14-Apr-20"
"15-Apr-20"
"16-Apr-20"
"17-Apr-20"
"18-Apr-20"
"19-Apr-20"
"20-Apr-20"
"21-Apr-20"
"22-Apr-20"
"23-Apr-20"
"24-Apr-20"
"25-Apr-20"
"26-Apr-20"
"27-Apr-20"
"28-Apr-20"
"29-Apr-20"
"30-Apr-20"
"01-May-20"
"02-May-20"
"03-May-20"
"04-May-20"
"05-May-20"
"06-May-20"
error encounter below
Error using datetime (line 667)
Unable to convert the text to datetime using the format ‘dd/MM/yy’.
Error in Q3 (line 13)
dates=datetime(dates,’InputFormat’,’dd/MM/yy’); %convert date strings to date time format dates=string(raw.textdata(2:end,1));%import the string dates from the data
dates=datetime(dates,’InputFormat’,’dd/MM/yy’); %convert date strings to date time format
%monthly vectors
m=unique(month(dates));%Get unique months form the data set
m_sum_Production=zeros(length(m),1);%initial monthly sum of Production
m_sum_T_Consumption=zeros(length(m),1);%initial monthly sum of Total Consumption
m_sum_O_Consumption=zeros(length(m),1);%initial monthly sum of Own Consumption
for i =1:length(m)
current_months=month(dates)==m(i); %checks each date to see if its month matches the current month
m_sum_Production(i) = sum(Production(current_months));%monthly sum of Production
m_sum_T_Consumption(i) = sum(T_Consumption(current_months));%monthly sum of Total Consumption
m_sum_O_Consumption(i) = sum(O_Consumption(current_months));%monthly sum of Own Consumption
end
code above
dates =
1505×1 string array
"06-Apr-20"
"07-Apr-20"
"08-Apr-20"
"09-Apr-20"
"10-Apr-20"
"11-Apr-20"
"12-Apr-20"
"13-Apr-20"
"14-Apr-20"
"15-Apr-20"
"16-Apr-20"
"17-Apr-20"
"18-Apr-20"
"19-Apr-20"
"20-Apr-20"
"21-Apr-20"
"22-Apr-20"
"23-Apr-20"
"24-Apr-20"
"25-Apr-20"
"26-Apr-20"
"27-Apr-20"
"28-Apr-20"
"29-Apr-20"
"30-Apr-20"
"01-May-20"
"02-May-20"
"03-May-20"
"04-May-20"
"05-May-20"
"06-May-20"
error encounter below
Error using datetime (line 667)
Unable to convert the text to datetime using the format ‘dd/MM/yy’.
Error in Q3 (line 13)
dates=datetime(dates,’InputFormat’,’dd/MM/yy’); %convert date strings to date time format datetime MATLAB Answers — New Questions
Can I use a struct in an anonymous function?
I am solving a PDE via finite volume methods. As a result, I am left with a set of ODEs which I solve with ode15s. I have a bunch of constants which I use in the function defining the derivative, and I insert these by the inclusion of a struct to the function. When I run the ode15s I obtain an error which pertains to the inclusion of the struct as an input to the function. I don’t really want to include the constants within the function as that seems "messy", so I would prefer to do it via a struct.
%This is a code to solve the isothermal sintering equations.
%%—Physical parameters—
S=struct;
S.g = 9.81; %Acceleration due to gravity.
S.K = 1; %This is the Laplace constant from the sintering potential.
S.eta_0 = 1; %The shear stress of the skeleton
S.T = 3600; %This is the time of sintering.
S.M = 0.1; %This is the total mass of the rod being sintered .
S.rho_m = 1; %This is the density of the individual metallic particles.
S.N = 251; %This is the number of cells-1
L = 1; %This is the initial length of the rod
%%—Initial conditions
%Length
X=linspace(0,L,S.N); %This is the partition of the initial length
%Density
rho_0=0.5+0.1*sin(6*pi*X);
%Amount of mass
S.h=cumtrapz(X,rho_0);
%Initial velocity
u0=zeros(S.N-1,1);
% Define the system of equations as a function
y0 = [1./rho_0′; u0];
% Finite Volume Method solution loop
tspan = [0 3]; % You can adjust this based on the time range you’re interested in
[t, y] = ode15s(@ode_system, tspan, y0);
function dydt = ode_system(t, y, S)
S.M
U=S.M/(S.rho_m*S.T);
a_1=S.T/(U*S.M);
a_2=S.T*S.rho_m/S.M^2;
a_3=S.g*S.T/U;
dh=diff(S.h);
y=NaN(1,2*S.N-2);
nu = y(1:S.N-1); % u(t)
u = y(S.N:2*S.N-2); % v(t)
%Compute the left and right specific volumes:
nu_left=15*nu(1)/8-5*nu(2)/4+3*nu(3)/8;
nu_right=15*nu(S.N-3)/8-5*nu(S.N-2)/5+3*nu(S.N-1)/8;
%Compute the fluxes on the interfaces
nu_half=NaN(1:S.N);
nu_half(2:N-1)=0.5*(nu(2:S.N-1)+nu(1:S.N-2));
nu_half(1)=nu_left;
nu_half(N)=nu_right;
%Fluxes for nu equation
nu_flux=zeros(S.N,1);
nu_flux(2:S.N-1)=0.5*(u(1:S.N-2)+u(2:S.N-1));
du_dh_left=-P_L(S,nu_left)*nu_left/zeta(nu_left);
du_dh_right=-P_L(S,nu_right)*nu_right/zeta(nu_right);
nu_flux(1)=-3*du_dh_left*dh(1)/8+9*u(1)/8-u(2)/8;
nu_flux(N)=3*du_dh_right*dh(N-1)/8-9*u(N-1)/8+u(N-2)/8;
%Fluxes for u equation
u_grad=2*(u(2:S.N-2)-u(1:S.N-2))./(dh(2:S.N-1)+dh(1:S.N-2));
u_flux=NaN(S.N,1);
u_flux(2:S.N-1)=a_1*P_L(S,nu_half(2:S.N-1))+(a_2*zeta(nu_half(2:S.N-1))./nu_half(2:S.N-1)).*u_grad;
% The system of equationsY
dnu_dt = nu_flux(2:S.N)-nu_flux(1:S.N-1);
du_dt =u_flux(2:S.N)-u_flux(1:S.N-1);
% Return the derivatives
dydt = [dnu_dt; du_dt];
end
function y=P_L(S,nu)
y=S.K./nu;
end
function y=zeta(nu)
y=(2/3)*(nu).^(-2)./(nu-1);
endI am solving a PDE via finite volume methods. As a result, I am left with a set of ODEs which I solve with ode15s. I have a bunch of constants which I use in the function defining the derivative, and I insert these by the inclusion of a struct to the function. When I run the ode15s I obtain an error which pertains to the inclusion of the struct as an input to the function. I don’t really want to include the constants within the function as that seems "messy", so I would prefer to do it via a struct.
%This is a code to solve the isothermal sintering equations.
%%—Physical parameters—
S=struct;
S.g = 9.81; %Acceleration due to gravity.
S.K = 1; %This is the Laplace constant from the sintering potential.
S.eta_0 = 1; %The shear stress of the skeleton
S.T = 3600; %This is the time of sintering.
S.M = 0.1; %This is the total mass of the rod being sintered .
S.rho_m = 1; %This is the density of the individual metallic particles.
S.N = 251; %This is the number of cells-1
L = 1; %This is the initial length of the rod
%%—Initial conditions
%Length
X=linspace(0,L,S.N); %This is the partition of the initial length
%Density
rho_0=0.5+0.1*sin(6*pi*X);
%Amount of mass
S.h=cumtrapz(X,rho_0);
%Initial velocity
u0=zeros(S.N-1,1);
% Define the system of equations as a function
y0 = [1./rho_0′; u0];
% Finite Volume Method solution loop
tspan = [0 3]; % You can adjust this based on the time range you’re interested in
[t, y] = ode15s(@ode_system, tspan, y0);
function dydt = ode_system(t, y, S)
S.M
U=S.M/(S.rho_m*S.T);
a_1=S.T/(U*S.M);
a_2=S.T*S.rho_m/S.M^2;
a_3=S.g*S.T/U;
dh=diff(S.h);
y=NaN(1,2*S.N-2);
nu = y(1:S.N-1); % u(t)
u = y(S.N:2*S.N-2); % v(t)
%Compute the left and right specific volumes:
nu_left=15*nu(1)/8-5*nu(2)/4+3*nu(3)/8;
nu_right=15*nu(S.N-3)/8-5*nu(S.N-2)/5+3*nu(S.N-1)/8;
%Compute the fluxes on the interfaces
nu_half=NaN(1:S.N);
nu_half(2:N-1)=0.5*(nu(2:S.N-1)+nu(1:S.N-2));
nu_half(1)=nu_left;
nu_half(N)=nu_right;
%Fluxes for nu equation
nu_flux=zeros(S.N,1);
nu_flux(2:S.N-1)=0.5*(u(1:S.N-2)+u(2:S.N-1));
du_dh_left=-P_L(S,nu_left)*nu_left/zeta(nu_left);
du_dh_right=-P_L(S,nu_right)*nu_right/zeta(nu_right);
nu_flux(1)=-3*du_dh_left*dh(1)/8+9*u(1)/8-u(2)/8;
nu_flux(N)=3*du_dh_right*dh(N-1)/8-9*u(N-1)/8+u(N-2)/8;
%Fluxes for u equation
u_grad=2*(u(2:S.N-2)-u(1:S.N-2))./(dh(2:S.N-1)+dh(1:S.N-2));
u_flux=NaN(S.N,1);
u_flux(2:S.N-1)=a_1*P_L(S,nu_half(2:S.N-1))+(a_2*zeta(nu_half(2:S.N-1))./nu_half(2:S.N-1)).*u_grad;
% The system of equationsY
dnu_dt = nu_flux(2:S.N)-nu_flux(1:S.N-1);
du_dt =u_flux(2:S.N)-u_flux(1:S.N-1);
% Return the derivatives
dydt = [dnu_dt; du_dt];
end
function y=P_L(S,nu)
y=S.K./nu;
end
function y=zeta(nu)
y=(2/3)*(nu).^(-2)./(nu-1);
end I am solving a PDE via finite volume methods. As a result, I am left with a set of ODEs which I solve with ode15s. I have a bunch of constants which I use in the function defining the derivative, and I insert these by the inclusion of a struct to the function. When I run the ode15s I obtain an error which pertains to the inclusion of the struct as an input to the function. I don’t really want to include the constants within the function as that seems "messy", so I would prefer to do it via a struct.
%This is a code to solve the isothermal sintering equations.
%%—Physical parameters—
S=struct;
S.g = 9.81; %Acceleration due to gravity.
S.K = 1; %This is the Laplace constant from the sintering potential.
S.eta_0 = 1; %The shear stress of the skeleton
S.T = 3600; %This is the time of sintering.
S.M = 0.1; %This is the total mass of the rod being sintered .
S.rho_m = 1; %This is the density of the individual metallic particles.
S.N = 251; %This is the number of cells-1
L = 1; %This is the initial length of the rod
%%—Initial conditions
%Length
X=linspace(0,L,S.N); %This is the partition of the initial length
%Density
rho_0=0.5+0.1*sin(6*pi*X);
%Amount of mass
S.h=cumtrapz(X,rho_0);
%Initial velocity
u0=zeros(S.N-1,1);
% Define the system of equations as a function
y0 = [1./rho_0′; u0];
% Finite Volume Method solution loop
tspan = [0 3]; % You can adjust this based on the time range you’re interested in
[t, y] = ode15s(@ode_system, tspan, y0);
function dydt = ode_system(t, y, S)
S.M
U=S.M/(S.rho_m*S.T);
a_1=S.T/(U*S.M);
a_2=S.T*S.rho_m/S.M^2;
a_3=S.g*S.T/U;
dh=diff(S.h);
y=NaN(1,2*S.N-2);
nu = y(1:S.N-1); % u(t)
u = y(S.N:2*S.N-2); % v(t)
%Compute the left and right specific volumes:
nu_left=15*nu(1)/8-5*nu(2)/4+3*nu(3)/8;
nu_right=15*nu(S.N-3)/8-5*nu(S.N-2)/5+3*nu(S.N-1)/8;
%Compute the fluxes on the interfaces
nu_half=NaN(1:S.N);
nu_half(2:N-1)=0.5*(nu(2:S.N-1)+nu(1:S.N-2));
nu_half(1)=nu_left;
nu_half(N)=nu_right;
%Fluxes for nu equation
nu_flux=zeros(S.N,1);
nu_flux(2:S.N-1)=0.5*(u(1:S.N-2)+u(2:S.N-1));
du_dh_left=-P_L(S,nu_left)*nu_left/zeta(nu_left);
du_dh_right=-P_L(S,nu_right)*nu_right/zeta(nu_right);
nu_flux(1)=-3*du_dh_left*dh(1)/8+9*u(1)/8-u(2)/8;
nu_flux(N)=3*du_dh_right*dh(N-1)/8-9*u(N-1)/8+u(N-2)/8;
%Fluxes for u equation
u_grad=2*(u(2:S.N-2)-u(1:S.N-2))./(dh(2:S.N-1)+dh(1:S.N-2));
u_flux=NaN(S.N,1);
u_flux(2:S.N-1)=a_1*P_L(S,nu_half(2:S.N-1))+(a_2*zeta(nu_half(2:S.N-1))./nu_half(2:S.N-1)).*u_grad;
% The system of equationsY
dnu_dt = nu_flux(2:S.N)-nu_flux(1:S.N-1);
du_dt =u_flux(2:S.N)-u_flux(1:S.N-1);
% Return the derivatives
dydt = [dnu_dt; du_dt];
end
function y=P_L(S,nu)
y=S.K./nu;
end
function y=zeta(nu)
y=(2/3)*(nu).^(-2)./(nu-1);
end anonymous, function MATLAB Answers — New Questions
Writing an exponential equation in the title
I would like to write my exponential equation in the title of my figure. Right now I have:
title([‘y = ‘,num2str(a),’ x^’, (num2str(n))]);
The problem is my equation comes out as: y = 8.56 x^(0).68, which is not what I want.
I want would the title to be y = 8.56 x^(0.68). How do I do this?I would like to write my exponential equation in the title of my figure. Right now I have:
title([‘y = ‘,num2str(a),’ x^’, (num2str(n))]);
The problem is my equation comes out as: y = 8.56 x^(0).68, which is not what I want.
I want would the title to be y = 8.56 x^(0.68). How do I do this? I would like to write my exponential equation in the title of my figure. Right now I have:
title([‘y = ‘,num2str(a),’ x^’, (num2str(n))]);
The problem is my equation comes out as: y = 8.56 x^(0).68, which is not what I want.
I want would the title to be y = 8.56 x^(0.68). How do I do this? num2str MATLAB Answers — New Questions
Bandpass filter Transient Response. How to get rid of it?
I created this bandpass filter and plotted it’s impulse response:
% Bandpass filter parameters
f_nyquist = sampling_frequency / 2;
low_cutoff_frequency = 6; % Low cutoff frequency in Hz
high_cutoff_frequency = 400; % High cutoff frequency in Hz
% Design the bandpass filter
[b, a_filter] = butter(2, [low_cutoff_frequency, high_cutoff_frequency] / (f_nyquist), ‘bandpass’);
% Create an impulse signal (Dirac delta function)
impulse_signal = zeros(1, 1000); % Change 1000 to the desired length
impulse_signal(1) = 1; % Set the first sample to 1
% Apply bandpass filter to the impulse signal
impulse_response = filtfilt(b, a_filter, impulse_signal);
% Time vector for plotting
time = (0:length(impulse_response)-1) / sampling_frequency;
% Plot the impulse response
figure(‘Name’, ‘Impulse Response of the Bandpass Filter’);
plot(time, impulse_response);
title(‘Impulse Response of the Bandpass Filter’);
xlabel(‘Time (s)’);
ylabel(‘Amplitude’);
grid on;
[h, f] = freqz(b, a_filter, 1024, ‘whole’); % Frequency response
figure;
plot(f/pi * (sampling_frequency/2), abs(h)); % Plot magnitude response
xlabel(‘Frequency (Hz)’);
ylabel(‘Magnitude’);
title(‘Frequency Response of the Bandpass Filter’);
grid on;
Why is there a spike from zero to -0.1?
That’s the bandpass filtered sEMG signal. How can I remove the information that may be the transient response around 0 and the info around 4 seconds where I attenuate my signal in order to not include the switch (stop of an experiment)?
That’s the impulse response of the bandpass filter.I created this bandpass filter and plotted it’s impulse response:
% Bandpass filter parameters
f_nyquist = sampling_frequency / 2;
low_cutoff_frequency = 6; % Low cutoff frequency in Hz
high_cutoff_frequency = 400; % High cutoff frequency in Hz
% Design the bandpass filter
[b, a_filter] = butter(2, [low_cutoff_frequency, high_cutoff_frequency] / (f_nyquist), ‘bandpass’);
% Create an impulse signal (Dirac delta function)
impulse_signal = zeros(1, 1000); % Change 1000 to the desired length
impulse_signal(1) = 1; % Set the first sample to 1
% Apply bandpass filter to the impulse signal
impulse_response = filtfilt(b, a_filter, impulse_signal);
% Time vector for plotting
time = (0:length(impulse_response)-1) / sampling_frequency;
% Plot the impulse response
figure(‘Name’, ‘Impulse Response of the Bandpass Filter’);
plot(time, impulse_response);
title(‘Impulse Response of the Bandpass Filter’);
xlabel(‘Time (s)’);
ylabel(‘Amplitude’);
grid on;
[h, f] = freqz(b, a_filter, 1024, ‘whole’); % Frequency response
figure;
plot(f/pi * (sampling_frequency/2), abs(h)); % Plot magnitude response
xlabel(‘Frequency (Hz)’);
ylabel(‘Magnitude’);
title(‘Frequency Response of the Bandpass Filter’);
grid on;
Why is there a spike from zero to -0.1?
That’s the bandpass filtered sEMG signal. How can I remove the information that may be the transient response around 0 and the info around 4 seconds where I attenuate my signal in order to not include the switch (stop of an experiment)?
That’s the impulse response of the bandpass filter. I created this bandpass filter and plotted it’s impulse response:
% Bandpass filter parameters
f_nyquist = sampling_frequency / 2;
low_cutoff_frequency = 6; % Low cutoff frequency in Hz
high_cutoff_frequency = 400; % High cutoff frequency in Hz
% Design the bandpass filter
[b, a_filter] = butter(2, [low_cutoff_frequency, high_cutoff_frequency] / (f_nyquist), ‘bandpass’);
% Create an impulse signal (Dirac delta function)
impulse_signal = zeros(1, 1000); % Change 1000 to the desired length
impulse_signal(1) = 1; % Set the first sample to 1
% Apply bandpass filter to the impulse signal
impulse_response = filtfilt(b, a_filter, impulse_signal);
% Time vector for plotting
time = (0:length(impulse_response)-1) / sampling_frequency;
% Plot the impulse response
figure(‘Name’, ‘Impulse Response of the Bandpass Filter’);
plot(time, impulse_response);
title(‘Impulse Response of the Bandpass Filter’);
xlabel(‘Time (s)’);
ylabel(‘Amplitude’);
grid on;
[h, f] = freqz(b, a_filter, 1024, ‘whole’); % Frequency response
figure;
plot(f/pi * (sampling_frequency/2), abs(h)); % Plot magnitude response
xlabel(‘Frequency (Hz)’);
ylabel(‘Magnitude’);
title(‘Frequency Response of the Bandpass Filter’);
grid on;
Why is there a spike from zero to -0.1?
That’s the bandpass filtered sEMG signal. How can I remove the information that may be the transient response around 0 and the info around 4 seconds where I attenuate my signal in order to not include the switch (stop of an experiment)?
That’s the impulse response of the bandpass filter. bandpass filter, impulse response, emg signals, transient response MATLAB Answers — New Questions
control simulink panel dashboard programmatically
I want to create an application using simulink dashboards wich are put in panel.
is there any documentation on parameters that i can set using set_param on this panel?
ThanksI want to create an application using simulink dashboards wich are put in panel.
is there any documentation on parameters that i can set using set_param on this panel?
Thanks I want to create an application using simulink dashboards wich are put in panel.
is there any documentation on parameters that i can set using set_param on this panel?
Thanks dashboard simulink panel MATLAB Answers — New Questions
how to plot x y over time
this is te first time i used MATLAB i have eyetrack record like this
eyetrackRecord =
struct with fields:
x: [1.3756e+03 1.3734e+03 1.3798e+03 1.3789e+03 … ] (1×5128 double)
y: [416.1000 415.5000 416.6000 410.8000 … ] (1×5128 double)
pa: [1416 1423 1423 1421 1420 1424 1431 1417 … ] (1×5128 double)
t: [281349 281395 281403 281409 281418 281423 … ] (1×5128 double)
missing: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 … ] (1×5128 double)
How can I plot the moving heatmap of gazing over the video file in MATLABthis is te first time i used MATLAB i have eyetrack record like this
eyetrackRecord =
struct with fields:
x: [1.3756e+03 1.3734e+03 1.3798e+03 1.3789e+03 … ] (1×5128 double)
y: [416.1000 415.5000 416.6000 410.8000 … ] (1×5128 double)
pa: [1416 1423 1423 1421 1420 1424 1431 1417 … ] (1×5128 double)
t: [281349 281395 281403 281409 281418 281423 … ] (1×5128 double)
missing: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 … ] (1×5128 double)
How can I plot the moving heatmap of gazing over the video file in MATLAB this is te first time i used MATLAB i have eyetrack record like this
eyetrackRecord =
struct with fields:
x: [1.3756e+03 1.3734e+03 1.3798e+03 1.3789e+03 … ] (1×5128 double)
y: [416.1000 415.5000 416.6000 410.8000 … ] (1×5128 double)
pa: [1416 1423 1423 1421 1420 1424 1431 1417 … ] (1×5128 double)
t: [281349 281395 281403 281409 281418 281423 … ] (1×5128 double)
missing: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 … ] (1×5128 double)
How can I plot the moving heatmap of gazing over the video file in MATLAB eyetracking, heatmap, video MATLAB Answers — New Questions
i have completed matlab on ramp , got a progress report , is there a way i can get a certificate for the same
i have completed matlab on ramp part of WILP by Bits , got a progress report , is there a way to get a certificate?i have completed matlab on ramp part of WILP by Bits , got a progress report , is there a way to get a certificate? i have completed matlab on ramp part of WILP by Bits , got a progress report , is there a way to get a certificate? wilp, bits MATLAB Answers — New Questions
How can I define the additive process noise for optimal tuning?
Hallo everyone,
I’m following this example(in link) in Matlab to make ego location. In extended Kalman Filter, if I use fucntion-helpTuneinsEKF of example, matlab always reminds me that the matrix is singular in the accuracy of the calculation. I try to redefine the initial value of additive process noise for optimal tuning, but I habe no idea how can I define these values like additive process noise for orientation and…
apnoise(stateinfo(filter, "Orientation")) = [0.02014531; 100; 7.0076611; 1.308652];
apnoise(stateinfo(filter, "AngularVelocity")) = [0.0007698; 100; 100];
thank you
Best regards
https://de.mathworks.com/help/driving/ug/ego-vehicle-localization-using-gps-and-imu-fusion-for-scenario-generation.htmlHallo everyone,
I’m following this example(in link) in Matlab to make ego location. In extended Kalman Filter, if I use fucntion-helpTuneinsEKF of example, matlab always reminds me that the matrix is singular in the accuracy of the calculation. I try to redefine the initial value of additive process noise for optimal tuning, but I habe no idea how can I define these values like additive process noise for orientation and…
apnoise(stateinfo(filter, "Orientation")) = [0.02014531; 100; 7.0076611; 1.308652];
apnoise(stateinfo(filter, "AngularVelocity")) = [0.0007698; 100; 100];
thank you
Best regards
https://de.mathworks.com/help/driving/ug/ego-vehicle-localization-using-gps-and-imu-fusion-for-scenario-generation.html Hallo everyone,
I’m following this example(in link) in Matlab to make ego location. In extended Kalman Filter, if I use fucntion-helpTuneinsEKF of example, matlab always reminds me that the matrix is singular in the accuracy of the calculation. I try to redefine the initial value of additive process noise for optimal tuning, but I habe no idea how can I define these values like additive process noise for orientation and…
apnoise(stateinfo(filter, "Orientation")) = [0.02014531; 100; 7.0076611; 1.308652];
apnoise(stateinfo(filter, "AngularVelocity")) = [0.0007698; 100; 100];
thank you
Best regards
https://de.mathworks.com/help/driving/ug/ego-vehicle-localization-using-gps-and-imu-fusion-for-scenario-generation.html extended kalman filter, ego location MATLAB Answers — New Questions
How to plot curve instead of straight line in MATLAB?
How do i make the yellow line curve instead of st. LineHow do i make the yellow line curve instead of st. Line How do i make the yellow line curve instead of st. Line brayton cycle, thermodynamics, curve fitting, spline, plotting MATLAB Answers — New Questions
process model in idproc starts below zero despite normalization and constraints
I am trying to estimate a second-order plus time delay (SOPTD) process model using MATLAB’s System Identification Toolbox. However, in some cases, the estimated model does not start from zero, even though my input data is normalized and clamped to ensure non-negative values. and somecases they start above zero
I have tried several steps to fix this:
Adding an offset to the normalized data to avoid negative values.
Setting the process gain (Kp) to 1 and fixing it.
Setting constraints on the time delay (Td) and ensuring it is non-negative
Despite these attempts, 5 out of my 20 plots still exhibit negative values at the start. I need help understanding why this happens and how to ensure the model never goes negative.I am trying to estimate a second-order plus time delay (SOPTD) process model using MATLAB’s System Identification Toolbox. However, in some cases, the estimated model does not start from zero, even though my input data is normalized and clamped to ensure non-negative values. and somecases they start above zero
I have tried several steps to fix this:
Adding an offset to the normalized data to avoid negative values.
Setting the process gain (Kp) to 1 and fixing it.
Setting constraints on the time delay (Td) and ensuring it is non-negative
Despite these attempts, 5 out of my 20 plots still exhibit negative values at the start. I need help understanding why this happens and how to ensure the model never goes negative. I am trying to estimate a second-order plus time delay (SOPTD) process model using MATLAB’s System Identification Toolbox. However, in some cases, the estimated model does not start from zero, even though my input data is normalized and clamped to ensure non-negative values. and somecases they start above zero
I have tried several steps to fix this:
Adding an offset to the normalized data to avoid negative values.
Setting the process gain (Kp) to 1 and fixing it.
Setting constraints on the time delay (Td) and ensuring it is non-negative
Despite these attempts, 5 out of my 20 plots still exhibit negative values at the start. I need help understanding why this happens and how to ensure the model never goes negative. idproc, procest, system identification toolbox, ma MATLAB Answers — New Questions
matlab串口接收数据大小达不到STMUART发送数据大小
我是用matlab接收来自STM32串口的数据,数据的发送速度是500Hz,在串口助手上验证过没有问题,但是如果使用matlab接收就会缺少大概6s的数据,这是我的读取函数function readSensorData(app, src, ~)
% 读取数据并将数据放入队列
while src.NumBytesAvailable >= 5
% currentTime = datetime(‘now’); % 串口数据到达时记录时间戳
tic
frameHeader = read(src, 2, "uint8");
toc
if frameHeader(1) == 0x55 && frameHeader(2) == 0xAA
fun_data = read(src, 2, "uint8");
len = fun_data(2);
if src.NumBytesAvailable >= len + 1
if len ~= 0
dataToSend = read(src, len, "uint8");
checksum = read(src, 1, "uint8");
% 计算校验
expectedChecksum = bitcmp(mod(sum([fun_data, dataToSend]), 256), ‘uint8’);
if (checksum == expectedChecksum)
app.processData(dataToSend)
end
end
end
else
read(src, 1, ‘uint8’);
end
end
end
其中app.processData执行内容已经被我关闭,可以忽略我是用matlab接收来自STM32串口的数据,数据的发送速度是500Hz,在串口助手上验证过没有问题,但是如果使用matlab接收就会缺少大概6s的数据,这是我的读取函数function readSensorData(app, src, ~)
% 读取数据并将数据放入队列
while src.NumBytesAvailable >= 5
% currentTime = datetime(‘now’); % 串口数据到达时记录时间戳
tic
frameHeader = read(src, 2, "uint8");
toc
if frameHeader(1) == 0x55 && frameHeader(2) == 0xAA
fun_data = read(src, 2, "uint8");
len = fun_data(2);
if src.NumBytesAvailable >= len + 1
if len ~= 0
dataToSend = read(src, len, "uint8");
checksum = read(src, 1, "uint8");
% 计算校验
expectedChecksum = bitcmp(mod(sum([fun_data, dataToSend]), 256), ‘uint8’);
if (checksum == expectedChecksum)
app.processData(dataToSend)
end
end
end
else
read(src, 1, ‘uint8’);
end
end
end
其中app.processData执行内容已经被我关闭,可以忽略 我是用matlab接收来自STM32串口的数据,数据的发送速度是500Hz,在串口助手上验证过没有问题,但是如果使用matlab接收就会缺少大概6s的数据,这是我的读取函数function readSensorData(app, src, ~)
% 读取数据并将数据放入队列
while src.NumBytesAvailable >= 5
% currentTime = datetime(‘now’); % 串口数据到达时记录时间戳
tic
frameHeader = read(src, 2, "uint8");
toc
if frameHeader(1) == 0x55 && frameHeader(2) == 0xAA
fun_data = read(src, 2, "uint8");
len = fun_data(2);
if src.NumBytesAvailable >= len + 1
if len ~= 0
dataToSend = read(src, len, "uint8");
checksum = read(src, 1, "uint8");
% 计算校验
expectedChecksum = bitcmp(mod(sum([fun_data, dataToSend]), 256), ‘uint8’);
if (checksum == expectedChecksum)
app.processData(dataToSend)
end
end
end
else
read(src, 1, ‘uint8’);
end
end
end
其中app.processData执行内容已经被我关闭,可以忽略 上位机,信号处理,stm32 MATLAB Answers — New Questions
get class name and plot it in variables window.
Hello everyone!
I have a question about create class
I want to have classname like this in variables window:
val = (classname)
nch: 4
N: 8192
F: 100
df: 0.012207
T: 81.92
dt: 0.01
quantity: force,acc
sifactor: 1
labels: 1F,1A
How can I do that? Thank you all.Hello everyone!
I have a question about create class
I want to have classname like this in variables window:
val = (classname)
nch: 4
N: 8192
F: 100
df: 0.012207
T: 81.92
dt: 0.01
quantity: force,acc
sifactor: 1
labels: 1F,1A
How can I do that? Thank you all. Hello everyone!
I have a question about create class
I want to have classname like this in variables window:
val = (classname)
nch: 4
N: 8192
F: 100
df: 0.012207
T: 81.92
dt: 0.01
quantity: force,acc
sifactor: 1
labels: 1F,1A
How can I do that? Thank you all. signal processing MATLAB Answers — New Questions
Modeling a manipulator with elastic joint in Simscape Multibody
I need to model in Simscape a single-link manipulator with an elastic joint (like in the figure).
I tried modeling this way but I am not sure it’s the smartest way. I used the block ‘Ideal Torque Source’ to simulate the motor torque.
Any suggestion?I need to model in Simscape a single-link manipulator with an elastic joint (like in the figure).
I tried modeling this way but I am not sure it’s the smartest way. I used the block ‘Ideal Torque Source’ to simulate the motor torque.
Any suggestion? I need to model in Simscape a single-link manipulator with an elastic joint (like in the figure).
I tried modeling this way but I am not sure it’s the smartest way. I used the block ‘Ideal Torque Source’ to simulate the motor torque.
Any suggestion? simscape, simscape multibody, joint, elastic joint MATLAB Answers — New Questions
i need a matlab code to detect a currency to determine wether it is fake or real.i need a code that can compare the new processed image to a database and any other code i can use.
%here are some of the codes.am i using the right codes?
%are there any other codes i can use?
clear all;
close all;
Ireal = imread(‘C:UsersNatiDesktopnati projectNew folderNew folderprogress natibirrIMG_20180513_10260.jpg’); % Real
Iscaned = imread(‘C:UsersNatiDesktopnati projectNew folderNew folderprogress natibirrIMG_20180513_102606.jpg’); % scaned
%%//Pre-analysis
hsvImageReal = rgb2hsv(Ireal);
hsvImagescaned = rgb2hsv(Iscaned);
figure;
imshow([hsvImageReal(:,:,1) hsvImageReal(:,:,2) hsvImageReal(:,:,3)]);
title(‘Real pre process’);
figure;
imshow([hsvImagescaned(:,:,1) hsvImagescaned(:,:,2) hsvImagescaned(:,:,3)]);
title(‘scaned’);
%%//Initial segmentation
croppedImageReal = hsvImageReal(:,90:95,:);
croppedImagescaned = hsvImagescaned(:,93:98,:);
satThresh = 0.4;
valThresh = 0.3;
BWImageReal = (croppedImageReal(:,:,2) > satThresh & croppedImageReal(:,:,3) < valThresh);
figure;
subplot(1,2,1);
imshow(BWImageReal);
title(‘Real initial seg’);
BWImagescaned = (croppedImagescaned(:,:,2) > satThresh & croppedImagescaned(:,:,3) < valThresh);
subplot(1,2,2);
imshow(BWImagescaned);
title(‘scaned’);
%%//Post-process
se = strel(‘line’, 6, 90);
BWImageCloseReal = imclose(BWImageReal, se);
BWImageClosescaned = imclose(BWImagescaned, se);
figure;
subplot(1,2,1);
imshow(BWImageCloseReal);
title(‘Real post process’);
subplot(1,2,2);
imshow(BWImageClosescaned);
title(‘scaned’);
%%//Area open the image
figure;
areaopenReal = bwareaopen(BWImageCloseReal, 15);
subplot(1,2,1);
imshow(areaopenReal);
title(‘Real area open image’);
subplot(1,2,2);
areaopenscaned = bwareaopen(BWImageClosescaned, 15);
imshow(areaopenscaned);
title(‘scaned’);
%//Count how many objects there are
[~,countReal] = bwlabel(areaopenReal);
[~,countscaned] = bwlabel(areaopenscaned);
disp([‘The total number of black lines for the real note is: ‘ num2str(countReal)]);
disp([‘The total number of black lines for the scaned note is: ‘ num2str(countscaned)]);
%%
% convert to gray scale
grt = rgb2gray(Ireal);
grs = rgb2gray(Iscaned);
% contrast enhance the gray image to emphasize dark lines in lighter background
grt = imadjust(grt);
grs = imadjust(grs);
% close rgb. choose a larger k. idea is to remove the dark line
k = 7;
se = ones(k);
Irealcl = imclose(Ireal, se);
Iscanedcl = imclose(Iscaned, se);
% convert closed image to gray scale
grtcl = rgb2gray(Irealcl);
grscl = rgb2gray(Iscanedcl);
% take the difference (closed-gray-scale – contrast-enhanced-gray-scale)
difft = grtcl – grt;
diffs = grscl – grs;
% take the projection of the difference
pt = sum(difft’);
pf = sum(diffs’);
% smooth the projection
ptfilt = conv(pt, ones(1, k)/k, ‘same’);
pffilt = conv(pf, ones(1, k)/k, ‘same’);
% threshold (multiplication by max element is just for visualization)
tht = (pt > graythresh(pt))*max(pt);
thf = (pf > graythresh(pf))*max(pf);
% get the number of segments.
[lblt, nt] = bwlabel(tht);
[lblf, nf] = bwlabel(thf);
figure,
subplot(2, 1, 1), imshow(difft’), title(‘difference image for solid line’)
subplot(2, 1, 2), imshow(diffs’), title(‘difference image for broken line’)
figure,
subplot(2, 1, 1), plot(1:length(pt), pt, 1:length(pt), ptfilt, 1:length(pt), tht),
title(‘solid line image’),
legend(‘projection’, ‘smoothed’, ‘thresholded’, ‘location’, ‘eastoutside’)
subplot(2, 1, 2), plot(1:length(pf), pf, 1:length(pf), pffilt, 1:length(pf), thf),
title(‘broken line image’),
legend(‘projection’, ‘smoothed’, ‘thresholded’, ‘location’, ‘eastoutside’)
%%%
%% //Extract the black strips for each image
blackStripReal = Ireal(:,200:725,:);
blackStripscaned = Iscaned(:,200:725,:);
figure;
subplot(1,3,1);
imshow(blackStripReal);
title(‘Real black stripe’);
subplot(1,3,2);
imshow(blackStripscaned);
title(‘scaned’);
%%%
%% //Convert into grayscale then threshold
blackStripReal = rgb2gray(blackStripReal);
blackStripscaned = rgb2gray(blackStripscaned);
figure;
subplot(1,3,1);
imshow(blackStripReal);
title(‘Realblack strip’);
subplot(1,3,2);
imshow(blackStripscaned);
title(‘scaned’);%here are some of the codes.am i using the right codes?
%are there any other codes i can use?
clear all;
close all;
Ireal = imread(‘C:UsersNatiDesktopnati projectNew folderNew folderprogress natibirrIMG_20180513_10260.jpg’); % Real
Iscaned = imread(‘C:UsersNatiDesktopnati projectNew folderNew folderprogress natibirrIMG_20180513_102606.jpg’); % scaned
%%//Pre-analysis
hsvImageReal = rgb2hsv(Ireal);
hsvImagescaned = rgb2hsv(Iscaned);
figure;
imshow([hsvImageReal(:,:,1) hsvImageReal(:,:,2) hsvImageReal(:,:,3)]);
title(‘Real pre process’);
figure;
imshow([hsvImagescaned(:,:,1) hsvImagescaned(:,:,2) hsvImagescaned(:,:,3)]);
title(‘scaned’);
%%//Initial segmentation
croppedImageReal = hsvImageReal(:,90:95,:);
croppedImagescaned = hsvImagescaned(:,93:98,:);
satThresh = 0.4;
valThresh = 0.3;
BWImageReal = (croppedImageReal(:,:,2) > satThresh & croppedImageReal(:,:,3) < valThresh);
figure;
subplot(1,2,1);
imshow(BWImageReal);
title(‘Real initial seg’);
BWImagescaned = (croppedImagescaned(:,:,2) > satThresh & croppedImagescaned(:,:,3) < valThresh);
subplot(1,2,2);
imshow(BWImagescaned);
title(‘scaned’);
%%//Post-process
se = strel(‘line’, 6, 90);
BWImageCloseReal = imclose(BWImageReal, se);
BWImageClosescaned = imclose(BWImagescaned, se);
figure;
subplot(1,2,1);
imshow(BWImageCloseReal);
title(‘Real post process’);
subplot(1,2,2);
imshow(BWImageClosescaned);
title(‘scaned’);
%%//Area open the image
figure;
areaopenReal = bwareaopen(BWImageCloseReal, 15);
subplot(1,2,1);
imshow(areaopenReal);
title(‘Real area open image’);
subplot(1,2,2);
areaopenscaned = bwareaopen(BWImageClosescaned, 15);
imshow(areaopenscaned);
title(‘scaned’);
%//Count how many objects there are
[~,countReal] = bwlabel(areaopenReal);
[~,countscaned] = bwlabel(areaopenscaned);
disp([‘The total number of black lines for the real note is: ‘ num2str(countReal)]);
disp([‘The total number of black lines for the scaned note is: ‘ num2str(countscaned)]);
%%
% convert to gray scale
grt = rgb2gray(Ireal);
grs = rgb2gray(Iscaned);
% contrast enhance the gray image to emphasize dark lines in lighter background
grt = imadjust(grt);
grs = imadjust(grs);
% close rgb. choose a larger k. idea is to remove the dark line
k = 7;
se = ones(k);
Irealcl = imclose(Ireal, se);
Iscanedcl = imclose(Iscaned, se);
% convert closed image to gray scale
grtcl = rgb2gray(Irealcl);
grscl = rgb2gray(Iscanedcl);
% take the difference (closed-gray-scale – contrast-enhanced-gray-scale)
difft = grtcl – grt;
diffs = grscl – grs;
% take the projection of the difference
pt = sum(difft’);
pf = sum(diffs’);
% smooth the projection
ptfilt = conv(pt, ones(1, k)/k, ‘same’);
pffilt = conv(pf, ones(1, k)/k, ‘same’);
% threshold (multiplication by max element is just for visualization)
tht = (pt > graythresh(pt))*max(pt);
thf = (pf > graythresh(pf))*max(pf);
% get the number of segments.
[lblt, nt] = bwlabel(tht);
[lblf, nf] = bwlabel(thf);
figure,
subplot(2, 1, 1), imshow(difft’), title(‘difference image for solid line’)
subplot(2, 1, 2), imshow(diffs’), title(‘difference image for broken line’)
figure,
subplot(2, 1, 1), plot(1:length(pt), pt, 1:length(pt), ptfilt, 1:length(pt), tht),
title(‘solid line image’),
legend(‘projection’, ‘smoothed’, ‘thresholded’, ‘location’, ‘eastoutside’)
subplot(2, 1, 2), plot(1:length(pf), pf, 1:length(pf), pffilt, 1:length(pf), thf),
title(‘broken line image’),
legend(‘projection’, ‘smoothed’, ‘thresholded’, ‘location’, ‘eastoutside’)
%%%
%% //Extract the black strips for each image
blackStripReal = Ireal(:,200:725,:);
blackStripscaned = Iscaned(:,200:725,:);
figure;
subplot(1,3,1);
imshow(blackStripReal);
title(‘Real black stripe’);
subplot(1,3,2);
imshow(blackStripscaned);
title(‘scaned’);
%%%
%% //Convert into grayscale then threshold
blackStripReal = rgb2gray(blackStripReal);
blackStripscaned = rgb2gray(blackStripscaned);
figure;
subplot(1,3,1);
imshow(blackStripReal);
title(‘Realblack strip’);
subplot(1,3,2);
imshow(blackStripscaned);
title(‘scaned’); %here are some of the codes.am i using the right codes?
%are there any other codes i can use?
clear all;
close all;
Ireal = imread(‘C:UsersNatiDesktopnati projectNew folderNew folderprogress natibirrIMG_20180513_10260.jpg’); % Real
Iscaned = imread(‘C:UsersNatiDesktopnati projectNew folderNew folderprogress natibirrIMG_20180513_102606.jpg’); % scaned
%%//Pre-analysis
hsvImageReal = rgb2hsv(Ireal);
hsvImagescaned = rgb2hsv(Iscaned);
figure;
imshow([hsvImageReal(:,:,1) hsvImageReal(:,:,2) hsvImageReal(:,:,3)]);
title(‘Real pre process’);
figure;
imshow([hsvImagescaned(:,:,1) hsvImagescaned(:,:,2) hsvImagescaned(:,:,3)]);
title(‘scaned’);
%%//Initial segmentation
croppedImageReal = hsvImageReal(:,90:95,:);
croppedImagescaned = hsvImagescaned(:,93:98,:);
satThresh = 0.4;
valThresh = 0.3;
BWImageReal = (croppedImageReal(:,:,2) > satThresh & croppedImageReal(:,:,3) < valThresh);
figure;
subplot(1,2,1);
imshow(BWImageReal);
title(‘Real initial seg’);
BWImagescaned = (croppedImagescaned(:,:,2) > satThresh & croppedImagescaned(:,:,3) < valThresh);
subplot(1,2,2);
imshow(BWImagescaned);
title(‘scaned’);
%%//Post-process
se = strel(‘line’, 6, 90);
BWImageCloseReal = imclose(BWImageReal, se);
BWImageClosescaned = imclose(BWImagescaned, se);
figure;
subplot(1,2,1);
imshow(BWImageCloseReal);
title(‘Real post process’);
subplot(1,2,2);
imshow(BWImageClosescaned);
title(‘scaned’);
%%//Area open the image
figure;
areaopenReal = bwareaopen(BWImageCloseReal, 15);
subplot(1,2,1);
imshow(areaopenReal);
title(‘Real area open image’);
subplot(1,2,2);
areaopenscaned = bwareaopen(BWImageClosescaned, 15);
imshow(areaopenscaned);
title(‘scaned’);
%//Count how many objects there are
[~,countReal] = bwlabel(areaopenReal);
[~,countscaned] = bwlabel(areaopenscaned);
disp([‘The total number of black lines for the real note is: ‘ num2str(countReal)]);
disp([‘The total number of black lines for the scaned note is: ‘ num2str(countscaned)]);
%%
% convert to gray scale
grt = rgb2gray(Ireal);
grs = rgb2gray(Iscaned);
% contrast enhance the gray image to emphasize dark lines in lighter background
grt = imadjust(grt);
grs = imadjust(grs);
% close rgb. choose a larger k. idea is to remove the dark line
k = 7;
se = ones(k);
Irealcl = imclose(Ireal, se);
Iscanedcl = imclose(Iscaned, se);
% convert closed image to gray scale
grtcl = rgb2gray(Irealcl);
grscl = rgb2gray(Iscanedcl);
% take the difference (closed-gray-scale – contrast-enhanced-gray-scale)
difft = grtcl – grt;
diffs = grscl – grs;
% take the projection of the difference
pt = sum(difft’);
pf = sum(diffs’);
% smooth the projection
ptfilt = conv(pt, ones(1, k)/k, ‘same’);
pffilt = conv(pf, ones(1, k)/k, ‘same’);
% threshold (multiplication by max element is just for visualization)
tht = (pt > graythresh(pt))*max(pt);
thf = (pf > graythresh(pf))*max(pf);
% get the number of segments.
[lblt, nt] = bwlabel(tht);
[lblf, nf] = bwlabel(thf);
figure,
subplot(2, 1, 1), imshow(difft’), title(‘difference image for solid line’)
subplot(2, 1, 2), imshow(diffs’), title(‘difference image for broken line’)
figure,
subplot(2, 1, 1), plot(1:length(pt), pt, 1:length(pt), ptfilt, 1:length(pt), tht),
title(‘solid line image’),
legend(‘projection’, ‘smoothed’, ‘thresholded’, ‘location’, ‘eastoutside’)
subplot(2, 1, 2), plot(1:length(pf), pf, 1:length(pf), pffilt, 1:length(pf), thf),
title(‘broken line image’),
legend(‘projection’, ‘smoothed’, ‘thresholded’, ‘location’, ‘eastoutside’)
%%%
%% //Extract the black strips for each image
blackStripReal = Ireal(:,200:725,:);
blackStripscaned = Iscaned(:,200:725,:);
figure;
subplot(1,3,1);
imshow(blackStripReal);
title(‘Real black stripe’);
subplot(1,3,2);
imshow(blackStripscaned);
title(‘scaned’);
%%%
%% //Convert into grayscale then threshold
blackStripReal = rgb2gray(blackStripReal);
blackStripscaned = rgb2gray(blackStripscaned);
figure;
subplot(1,3,1);
imshow(blackStripReal);
title(‘Realblack strip’);
subplot(1,3,2);
imshow(blackStripscaned);
title(‘scaned’); fake currency detection system., currency, fake currency MATLAB Answers — New Questions
n-Channel Mosfet 3-D Lookup table, temperature dependent parameterization. Problems simulating different temperatures
Hello, I am trying to simulate the behavior of a MOSFET at different temperatures (25ºC and 17ºC), but I am having some issues. I have chosen the n-Channel MOSFET model from the Simulink library and below I attach the circuit and the parameters I have used based on the curves provided by the manufacturer.
The parameterization used is a 3-D Lookup table, temperature dependent, and in the following image, you can see the matrix used for IDs (datos_Ids) which depends on Vgs, Vds, and T.
When the simulation is run, even if the value in Temperature Source is changed, the same simulation always results; it seems to be independent of the temperature.
Any suggestions?
Thank you very muchHello, I am trying to simulate the behavior of a MOSFET at different temperatures (25ºC and 17ºC), but I am having some issues. I have chosen the n-Channel MOSFET model from the Simulink library and below I attach the circuit and the parameters I have used based on the curves provided by the manufacturer.
The parameterization used is a 3-D Lookup table, temperature dependent, and in the following image, you can see the matrix used for IDs (datos_Ids) which depends on Vgs, Vds, and T.
When the simulation is run, even if the value in Temperature Source is changed, the same simulation always results; it seems to be independent of the temperature.
Any suggestions?
Thank you very much Hello, I am trying to simulate the behavior of a MOSFET at different temperatures (25ºC and 17ºC), but I am having some issues. I have chosen the n-Channel MOSFET model from the Simulink library and below I attach the circuit and the parameters I have used based on the curves provided by the manufacturer.
The parameterization used is a 3-D Lookup table, temperature dependent, and in the following image, you can see the matrix used for IDs (datos_Ids) which depends on Vgs, Vds, and T.
When the simulation is run, even if the value in Temperature Source is changed, the same simulation always results; it seems to be independent of the temperature.
Any suggestions?
Thank you very much 3-d lookup table, temperature dependent parameteri, n-channel mosfet MATLAB Answers — New Questions
having the same problem about the arrays
daily_savings=zeros(1505,1);%initial saving vectors
daily_earnings=zeros(1505,1);%initial earning vectors
% Loop through each day to calculate savings and earnings % total days is 1505 (Date from(06/04/20 to 19/05/24))
for i = 0:1504 % days1 starts from 0 so 0:1504
% Calculate daily savings
daily_savings(i + 1) = O_Consumption(i + 1).*Cost;
% Calculate daily earnings
if i <= 1212 % Up to July 31, 2023 (day index 1212)
daily_earnings(i + 1) = energy_out(i + 1).*Feed(i + 1);
else % From August 1, 2023 onwards
if e_out(i + 1) < 10
daily_earnings(i + 1) = e_out(i + 1).*Feed(i + 1);
else
daily_earnings(i + 1) = ((e_out(i + 1) – 10) / 100) + 0.88;
end
end
above is the codedaily_savings=zeros(1505,1);%initial saving vectors
daily_earnings=zeros(1505,1);%initial earning vectors
% Loop through each day to calculate savings and earnings % total days is 1505 (Date from(06/04/20 to 19/05/24))
for i = 0:1504 % days1 starts from 0 so 0:1504
% Calculate daily savings
daily_savings(i + 1) = O_Consumption(i + 1).*Cost;
% Calculate daily earnings
if i <= 1212 % Up to July 31, 2023 (day index 1212)
daily_earnings(i + 1) = energy_out(i + 1).*Feed(i + 1);
else % From August 1, 2023 onwards
if e_out(i + 1) < 10
daily_earnings(i + 1) = e_out(i + 1).*Feed(i + 1);
else
daily_earnings(i + 1) = ((e_out(i + 1) – 10) / 100) + 0.88;
end
end
above is the code daily_savings=zeros(1505,1);%initial saving vectors
daily_earnings=zeros(1505,1);%initial earning vectors
% Loop through each day to calculate savings and earnings % total days is 1505 (Date from(06/04/20 to 19/05/24))
for i = 0:1504 % days1 starts from 0 so 0:1504
% Calculate daily savings
daily_savings(i + 1) = O_Consumption(i + 1).*Cost;
% Calculate daily earnings
if i <= 1212 % Up to July 31, 2023 (day index 1212)
daily_earnings(i + 1) = energy_out(i + 1).*Feed(i + 1);
else % From August 1, 2023 onwards
if e_out(i + 1) < 10
daily_earnings(i + 1) = e_out(i + 1).*Feed(i + 1);
else
daily_earnings(i + 1) = ((e_out(i + 1) – 10) / 100) + 0.88;
end
end
above is the code array, error MATLAB Answers — New Questions