Tag Archives: matlab
Enforce condition in lsqnoneg
I working on inverse problem which is rank deficient and for that i am using tikhonov regularization , for minization i am using lsqnoneg to resolve it which is giving me good result but now i have to enforce a condition in each iteration of minimzation of lsqnoneg, however lsqnoneg oterations are automatic i cant control it manually althohg i used fmincon but it is not giving me the same results can some one help what algorithm should i use so that i can enforce my conditon during optimization iterations and it gives results like lsqnoneg,
Tikh_Output.IA_recovered_line_1 = lsqnonneg(Combined_Coeff_Matrix,Combined_projection_line_1);
Tikh_Output.IA_recovered_line_2 = lsqnonneg(Combined_Coeff_Matrix,Combined_projection_line_2);
here is my codeI working on inverse problem which is rank deficient and for that i am using tikhonov regularization , for minization i am using lsqnoneg to resolve it which is giving me good result but now i have to enforce a condition in each iteration of minimzation of lsqnoneg, however lsqnoneg oterations are automatic i cant control it manually althohg i used fmincon but it is not giving me the same results can some one help what algorithm should i use so that i can enforce my conditon during optimization iterations and it gives results like lsqnoneg,
Tikh_Output.IA_recovered_line_1 = lsqnonneg(Combined_Coeff_Matrix,Combined_projection_line_1);
Tikh_Output.IA_recovered_line_2 = lsqnonneg(Combined_Coeff_Matrix,Combined_projection_line_2);
here is my code I working on inverse problem which is rank deficient and for that i am using tikhonov regularization , for minization i am using lsqnoneg to resolve it which is giving me good result but now i have to enforce a condition in each iteration of minimzation of lsqnoneg, however lsqnoneg oterations are automatic i cant control it manually althohg i used fmincon but it is not giving me the same results can some one help what algorithm should i use so that i can enforce my conditon during optimization iterations and it gives results like lsqnoneg,
Tikh_Output.IA_recovered_line_1 = lsqnonneg(Combined_Coeff_Matrix,Combined_projection_line_1);
Tikh_Output.IA_recovered_line_2 = lsqnonneg(Combined_Coeff_Matrix,Combined_projection_line_2);
here is my code lsqnoneg, tikhonov, matlab, enforcecondition MATLAB Answers — New Questions
how to find DFT , DTFT and DFS of a continuous time signal?
i need to find thee DFT,DTFT and DFS of a continuous time signal, x(t)=sin200pit+3cos100piti need to find thee DFT,DTFT and DFS of a continuous time signal, x(t)=sin200pit+3cos100pit i need to find thee DFT,DTFT and DFS of a continuous time signal, x(t)=sin200pit+3cos100pit dft, dtft, dfs MATLAB Answers — New Questions
I want to generate encoder output pulses from the angular velocity of a motor using simscape.
I want to reproduce the A and B phase pulses of the encoder using the Incremental Shaft Encoder in simscape’s Electrical. The angular velocity of the motor has an output signal in another model and I don’t know how to connect it to this simscape encoder.And it is not clear how to get phase A and B signals as simulink signals.I want to reproduce the A and B phase pulses of the encoder using the Incremental Shaft Encoder in simscape’s Electrical. The angular velocity of the motor has an output signal in another model and I don’t know how to connect it to this simscape encoder.And it is not clear how to get phase A and B signals as simulink signals. I want to reproduce the A and B phase pulses of the encoder using the Incremental Shaft Encoder in simscape’s Electrical. The angular velocity of the motor has an output signal in another model and I don’t know how to connect it to this simscape encoder.And it is not clear how to get phase A and B signals as simulink signals. simscape, electric_motor_control, simulink, encoder MATLAB Answers — New Questions
Desktop Real-Time slow initialization
I am using the input from an mcc usb-231 daq to feed data into my simulink model through a function block. The issue I am running into is that when the simulation first starts up. it takes almost an entire minute before my simulation begins simulating through the desktop realtime kernal.
Here is my function block.
function output = fcn()
coder.extrinsic(‘daq’,’read’,’addinput’); %lets simulink know to read commands as MATLAB commands
d = daq(‘mcc’);
addinput(d,’Board0′,0,’Voltage’)
data = read(d,’OutputFormat’,’Matrix’);
output = zeros(1,1);
output = data(1,1);
Is there a way to get rid of this initialization buffer at the start?I am using the input from an mcc usb-231 daq to feed data into my simulink model through a function block. The issue I am running into is that when the simulation first starts up. it takes almost an entire minute before my simulation begins simulating through the desktop realtime kernal.
Here is my function block.
function output = fcn()
coder.extrinsic(‘daq’,’read’,’addinput’); %lets simulink know to read commands as MATLAB commands
d = daq(‘mcc’);
addinput(d,’Board0′,0,’Voltage’)
data = read(d,’OutputFormat’,’Matrix’);
output = zeros(1,1);
output = data(1,1);
Is there a way to get rid of this initialization buffer at the start? I am using the input from an mcc usb-231 daq to feed data into my simulink model through a function block. The issue I am running into is that when the simulation first starts up. it takes almost an entire minute before my simulation begins simulating through the desktop realtime kernal.
Here is my function block.
function output = fcn()
coder.extrinsic(‘daq’,’read’,’addinput’); %lets simulink know to read commands as MATLAB commands
d = daq(‘mcc’);
addinput(d,’Board0′,0,’Voltage’)
data = read(d,’OutputFormat’,’Matrix’);
output = zeros(1,1);
output = data(1,1);
Is there a way to get rid of this initialization buffer at the start? simulink, data acquisition, matlab MATLAB Answers — New Questions
Using fminunc with ‘HessianMultiplyFcn’ option
I’m trying to solve a large-scale optimization problem using fminunc, where the number of variables is too large to store the Hessian explicitly.
I have carefully read the Matlab documention on using the ‘HessianMultiplyFcn’, which allows the user to pass in a function that will compute the Hessian times a vector Y. It says that in this case, the loss function should return the loss, gradient, and a struct called Hinfo.
However, MATLAB returns an error when using this function:
Error using fminunc (line 410)
FMINUNC requires all values returned by functions to be of data type double.
Note that I have set the algorithm to ‘trust-region’ and ‘HessianFcn’ to [] in optimoptions, so it should know that the third argument returned by my function is a struct.
Help! Has anyone encountered this before? Or can anyone post an example snippet in which they successfully used fminunc with the HessianMultiplyFcn option?
I’m copying the documentation for the HessianMultiplyFcn in the fminunc documentation in case it is helpful. (From:
—————-
HessianMultiplyFcn
Hessian multiply function, specified as a function handle. For large-scale structured problems, this function computes the Hessian matrix product H*Y without actually forming H. The function is of the form
W = hmfun(Hinfo,Y)
where Hinfo contains the matrix used to compute H*Y.
The first argument is the same as the third argument returned by the objective function fun, for example
[f,g,Hinfo] = fun(x)
Y is a matrix that has the same number of rows as there are dimensions in the problem. The matrix W = H*Y, although H is not formed explicitly. fminunc uses Hinfo to compute the preconditioner.I’m trying to solve a large-scale optimization problem using fminunc, where the number of variables is too large to store the Hessian explicitly.
I have carefully read the Matlab documention on using the ‘HessianMultiplyFcn’, which allows the user to pass in a function that will compute the Hessian times a vector Y. It says that in this case, the loss function should return the loss, gradient, and a struct called Hinfo.
However, MATLAB returns an error when using this function:
Error using fminunc (line 410)
FMINUNC requires all values returned by functions to be of data type double.
Note that I have set the algorithm to ‘trust-region’ and ‘HessianFcn’ to [] in optimoptions, so it should know that the third argument returned by my function is a struct.
Help! Has anyone encountered this before? Or can anyone post an example snippet in which they successfully used fminunc with the HessianMultiplyFcn option?
I’m copying the documentation for the HessianMultiplyFcn in the fminunc documentation in case it is helpful. (From:
—————-
HessianMultiplyFcn
Hessian multiply function, specified as a function handle. For large-scale structured problems, this function computes the Hessian matrix product H*Y without actually forming H. The function is of the form
W = hmfun(Hinfo,Y)
where Hinfo contains the matrix used to compute H*Y.
The first argument is the same as the third argument returned by the objective function fun, for example
[f,g,Hinfo] = fun(x)
Y is a matrix that has the same number of rows as there are dimensions in the problem. The matrix W = H*Y, although H is not formed explicitly. fminunc uses Hinfo to compute the preconditioner. I’m trying to solve a large-scale optimization problem using fminunc, where the number of variables is too large to store the Hessian explicitly.
I have carefully read the Matlab documention on using the ‘HessianMultiplyFcn’, which allows the user to pass in a function that will compute the Hessian times a vector Y. It says that in this case, the loss function should return the loss, gradient, and a struct called Hinfo.
However, MATLAB returns an error when using this function:
Error using fminunc (line 410)
FMINUNC requires all values returned by functions to be of data type double.
Note that I have set the algorithm to ‘trust-region’ and ‘HessianFcn’ to [] in optimoptions, so it should know that the third argument returned by my function is a struct.
Help! Has anyone encountered this before? Or can anyone post an example snippet in which they successfully used fminunc with the HessianMultiplyFcn option?
I’m copying the documentation for the HessianMultiplyFcn in the fminunc documentation in case it is helpful. (From:
—————-
HessianMultiplyFcn
Hessian multiply function, specified as a function handle. For large-scale structured problems, this function computes the Hessian matrix product H*Y without actually forming H. The function is of the form
W = hmfun(Hinfo,Y)
where Hinfo contains the matrix used to compute H*Y.
The first argument is the same as the third argument returned by the objective function fun, for example
[f,g,Hinfo] = fun(x)
Y is a matrix that has the same number of rows as there are dimensions in the problem. The matrix W = H*Y, although H is not formed explicitly. fminunc uses Hinfo to compute the preconditioner. fminunc, hessianmultiplyfcn MATLAB Answers — New Questions
Does anyone know how to convert AMESim .data files to SImulink supported files.
I want to convert AMESim software supported AMETable data (.data files) to Simulink Lookup tables suppoerted data. When I tried with the below code and applie to the N-D lookup table in simulink I am having the following error.
% ———————————————–
% This script is developed to convert the AMESim Looukp table to Simulink
% supported format.
% It supports the AMESim [ 1D, {2D, …. 8D}, T1D(Multi 1D),
% T3D (Multi M1D), XY tables conversion to Simulink format
% ———————————————–
% Input = "filename.data"
% Output = LUT —> is a structure
% —> LUT.BP.Breakpoint holds the Breakpoints data
% —> LUT.BP.Lenth holds the number of elements in each breakpoint
% —> LUT.BP.Table_data holds the table data
fname = uigetfile({‘*.data’;’*.txt’}, ‘Select the .data file for conversion’); % To get the file from the user
if fname == 0
error(‘User not selected the file for conversion’);
else
LUT = AMETable_2_Simulink(fname); % Function call to the conversion function
end
function LUT = AMETable_2_Simulink(fname)
fid = fopen(fname, "r", "ieee-le", "UTF-8");
file_data = fscanf(fid, ‘%c’);
delimited_file_data = strsplit(file_data, {‘n’})’; % Splitting the file data by using new line delimiter
fclose(fid);
LUT_Dimns = strtrim(extractAfter(delimited_file_data{1},"format:")); % Finding the Table format type
% Declaring the empty arrays
x_ele = []; y_ele = []; z_ele = []; T_ele = [];
x1 = []; x2 = []; x3 = []; tbl = [];
x = []; y = []; z = []; tbl_data = [];
LUT = struct;
switch LUT_Dimns
case ‘1D’
% For 1D AMETable —> 1D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i}) % Checking if it not an empty line
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line{1})) %
x = [x; split_line(1)]; % Breakpoints for the Lookup Table
tbl = [tbl; split_line(2)]; % Table for the Lookup Table
end
end
end
LUT.BP.Breakpoint = str2double(x)’;
LUT.Table_data = str2double(tbl)’;
case ‘T1D’
% For T1D AMETable —> 2D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line{1}))
if length(split_line{2}) <= 3
x2 = [x2; str2double(split_line{1})]; % Breakpoints2 for the Lookup Table
else
x1 = [x1; str2double(split_line{1})]; % Breakpoints1 for the Lookup Table
tbl = [tbl; str2double(split_line{2})]; % Table for the Lookup Table
if ~eq(length(x2), length(x1))
intrpl_y = repelem(x2(end), (length(x1) – length(x2)))’;
x2 = [x2; intrpl_y]; % Breakpoints2 for the Lookup Table
end
end
end
end
end
arr = [x1, x2, tbl]; % Creating an array of all the data
a2tbl = array2table(arr, ‘VariableNames’, {‘X_axis’, ‘Y_axis’, ‘Tabledata’}); % Converting array2table
y = sort(unique(x2));
x = sort(unique(x1));
% Sorting the data in ascending order and assing the NAN values to the missing MAPS
for k = 1:length(x)
xx = x(k);
for l = 1:length(y)
yy = y(l);
table_indxed = a2tbl(a2tbl.X_axis == xx & a2tbl.Y_axis == yy, :);
if isempty(table_indxed)
table_indxed = table(xx, yy, NaN, ‘VariableNames’, …
{‘X_axis’, ‘Y_axis’, ‘Tabledata’});
end
if ~exist(‘manpltd_tbl’, ‘var’)
manpltd_tbl = table_indxed;
else
manpltd_tbl = [manpltd_tbl; table_indxed];
end
end
end
% Filling the missing MAPS with the nearest values of the MAPS
manpltd_tbl.Tabledata = fillmissing(manpltd_tbl.Tabledata, ‘nearest’);
% Asigning the Breakpoints & Table_data to the Structure
LUT.BP(1).Breakpoint = unique(manpltd_tbl.X_axis);
LUT.BP(2).Breakpoint = unique(manpltd_tbl.Y_axis);
LUT.BP(1).Lenth = length(unique(manpltd_tbl.X_axis));
LUT.BP(2).Lenth = length(unique(manpltd_tbl.Y_axis));
LUT.Table_data = reshape(manpltd_tbl.Tabledata, LUT.BP(:).Lenth);
case ‘T3D’
% For T3D AMETable —> 3D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line{1}))
if length(split_line{2}) <= 3
next_split_line = strsplit(strtrim(delimited_file_data{i + 1}));
if length(next_split_line{2}) <= 3
x3 = [x3; str2double(split_line{1})]; % Breakpoints3 for the Lookup Table
else
x2 = [x2; str2double(split_line{1})]; % Breakpoints2 for the Lookup Table
end
else
x1 = [x1; str2double(split_line{1})]; % Breakpoints1 for the Lookup Table
tbl = [tbl; str2double(split_line{2})];
if ~eq(length(x2), length(x1))
intrpl_y = repelem(x2(end), (length(x1) – length(x2)))’;
x2 = [x2; intrpl_y]; % Breakpoints2 for the Lookup Table
end
if ~eq(length(x3), length(x1))
intrpl_z = repelem(x3(end), (length(x1) – length(x3)))’;
x3 = [x3; intrpl_z]; % Breakpoints3 for the Lookup Table
end
end
end
end
end
arr = [x1, x2, x3, tbl]; % Creating an array of all the data
a2tbl = array2table(arr, ‘VariableNames’, {‘X_axis’, ‘Y_axis’, ‘Z_axis’, ‘Tabledata’}); % Converting array2table
z = sort(unique(x3)); y = sort(unique(x2)); x = sort(unique(x1)); % Sorting of the data
% Sorting the data in ascending order and assing the NAN values to the missing MAPS
for k = 1:length(x)
xx = x(k);
for l = 1:length(y)
yy = y(l);
for m = 1:length(z)
zz = z(m);
table_indxed = a2tbl(a2tbl.X_axis == xx & a2tbl.Y_axis == yy & a2tbl.Z_axis == zz, :);
if isempty(table_indxed)
table_indxed = table(xx, yy, zz, NaN, ‘VariableNames’, …
{‘X_axis’, ‘Y_axis’, ‘Z_axis’, ‘Tabledata’});
end
if ~exist(‘manpltd_tbl’, ‘var’)
manpltd_tbl = table_indxed;
else
manpltd_tbl = [manpltd_tbl; table_indxed];
end
end
end
end
% Filling the missing MAPS with the nearest values of the MAPS
manpltd_tbl.Tabledata = fillmissing(manpltd_tbl.Tabledata, ‘nearest’);
% nanLocations = isnan(manpltd_tbl.Tabledata);
% nanLinearIndexes = find(nanLocations);
% nonNanLinearIndexes = setdiff(1:numel(manpltd_tbl.Tabledata), nanLinearIndexes);
% Filling the missing MAPS with the nearest values of the MAPS
LUT.BP(1).Breakpoint = unique(manpltd_tbl.X_axis);
LUT.BP(2).Breakpoint = unique(manpltd_tbl.Y_axis);
LUT.BP(3).Breakpoint = unique(manpltd_tbl.Z_axis);
LUT.BP(1).Lenth = length(unique(manpltd_tbl.X_axis));
LUT.BP(2).Lenth = length(unique(manpltd_tbl.Y_axis));
LUT.BP(3).Lenth = length(unique(manpltd_tbl.Z_axis));
LUT.Table_data = reshape(manpltd_tbl.Tabledata, LUT.BP(:).Lenth);
case ‘XY’
% For XY AMETable —> 1D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(delimited_file_data{i});
if ~isnan(str2double(split_line{2}))
x = [x; split_line{2}];
y = [y; split_line{3}];
z = [z; split_line{4}];
end
end
end
LUT.BP(1).Breakpoint = x;
LUT.BP(2).Breakpoint = y;
LUT.Table_data = z;
otherwise
% For {2D, 3D…. 8D] AMETable —> 4D Lookup Table
LUT_Dimns = str2double(deblank(extractBefore(LUT_Dimns, ‘D’)));
n = 1;
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line(~cellfun(‘isempty’,split_line))))
if (n <= LUT_Dimns)
if ~isfield(LUT, ‘BP’)
k = i;
end
for j = 1:LUT_Dimns
LUT.BP(n).Lenth = str2double(split_line(~cellfun(‘isempty’,split_line)));
split_BP = strsplit(delimited_file_data{i+LUT_Dimns});
LUT.BP(n).Breakpoint = str2double(split_BP(~cellfun(‘isempty’,split_BP)));
break
end
n = n+1;
elseif i >= ( k + 2*LUT_Dimns)
line_table_data = str2double(split_line(~cellfun(‘isempty’,split_line)));
tbl = [tbl; line_table_data];
end
end
end
end
for j = 1:size(tbl, 1)
if j == 1
conv_table_dta = transpose(tbl(j, :));
else
TransCol = transpose(tbl(j, :));
conv_table_dta = [conv_table_dta; TransCol];
end
end
LUT.Table_data = reshape(conv_table_dta, LUT.BP(:).Lenth);
end
endI want to convert AMESim software supported AMETable data (.data files) to Simulink Lookup tables suppoerted data. When I tried with the below code and applie to the N-D lookup table in simulink I am having the following error.
% ———————————————–
% This script is developed to convert the AMESim Looukp table to Simulink
% supported format.
% It supports the AMESim [ 1D, {2D, …. 8D}, T1D(Multi 1D),
% T3D (Multi M1D), XY tables conversion to Simulink format
% ———————————————–
% Input = "filename.data"
% Output = LUT —> is a structure
% —> LUT.BP.Breakpoint holds the Breakpoints data
% —> LUT.BP.Lenth holds the number of elements in each breakpoint
% —> LUT.BP.Table_data holds the table data
fname = uigetfile({‘*.data’;’*.txt’}, ‘Select the .data file for conversion’); % To get the file from the user
if fname == 0
error(‘User not selected the file for conversion’);
else
LUT = AMETable_2_Simulink(fname); % Function call to the conversion function
end
function LUT = AMETable_2_Simulink(fname)
fid = fopen(fname, "r", "ieee-le", "UTF-8");
file_data = fscanf(fid, ‘%c’);
delimited_file_data = strsplit(file_data, {‘n’})’; % Splitting the file data by using new line delimiter
fclose(fid);
LUT_Dimns = strtrim(extractAfter(delimited_file_data{1},"format:")); % Finding the Table format type
% Declaring the empty arrays
x_ele = []; y_ele = []; z_ele = []; T_ele = [];
x1 = []; x2 = []; x3 = []; tbl = [];
x = []; y = []; z = []; tbl_data = [];
LUT = struct;
switch LUT_Dimns
case ‘1D’
% For 1D AMETable —> 1D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i}) % Checking if it not an empty line
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line{1})) %
x = [x; split_line(1)]; % Breakpoints for the Lookup Table
tbl = [tbl; split_line(2)]; % Table for the Lookup Table
end
end
end
LUT.BP.Breakpoint = str2double(x)’;
LUT.Table_data = str2double(tbl)’;
case ‘T1D’
% For T1D AMETable —> 2D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line{1}))
if length(split_line{2}) <= 3
x2 = [x2; str2double(split_line{1})]; % Breakpoints2 for the Lookup Table
else
x1 = [x1; str2double(split_line{1})]; % Breakpoints1 for the Lookup Table
tbl = [tbl; str2double(split_line{2})]; % Table for the Lookup Table
if ~eq(length(x2), length(x1))
intrpl_y = repelem(x2(end), (length(x1) – length(x2)))’;
x2 = [x2; intrpl_y]; % Breakpoints2 for the Lookup Table
end
end
end
end
end
arr = [x1, x2, tbl]; % Creating an array of all the data
a2tbl = array2table(arr, ‘VariableNames’, {‘X_axis’, ‘Y_axis’, ‘Tabledata’}); % Converting array2table
y = sort(unique(x2));
x = sort(unique(x1));
% Sorting the data in ascending order and assing the NAN values to the missing MAPS
for k = 1:length(x)
xx = x(k);
for l = 1:length(y)
yy = y(l);
table_indxed = a2tbl(a2tbl.X_axis == xx & a2tbl.Y_axis == yy, :);
if isempty(table_indxed)
table_indxed = table(xx, yy, NaN, ‘VariableNames’, …
{‘X_axis’, ‘Y_axis’, ‘Tabledata’});
end
if ~exist(‘manpltd_tbl’, ‘var’)
manpltd_tbl = table_indxed;
else
manpltd_tbl = [manpltd_tbl; table_indxed];
end
end
end
% Filling the missing MAPS with the nearest values of the MAPS
manpltd_tbl.Tabledata = fillmissing(manpltd_tbl.Tabledata, ‘nearest’);
% Asigning the Breakpoints & Table_data to the Structure
LUT.BP(1).Breakpoint = unique(manpltd_tbl.X_axis);
LUT.BP(2).Breakpoint = unique(manpltd_tbl.Y_axis);
LUT.BP(1).Lenth = length(unique(manpltd_tbl.X_axis));
LUT.BP(2).Lenth = length(unique(manpltd_tbl.Y_axis));
LUT.Table_data = reshape(manpltd_tbl.Tabledata, LUT.BP(:).Lenth);
case ‘T3D’
% For T3D AMETable —> 3D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line{1}))
if length(split_line{2}) <= 3
next_split_line = strsplit(strtrim(delimited_file_data{i + 1}));
if length(next_split_line{2}) <= 3
x3 = [x3; str2double(split_line{1})]; % Breakpoints3 for the Lookup Table
else
x2 = [x2; str2double(split_line{1})]; % Breakpoints2 for the Lookup Table
end
else
x1 = [x1; str2double(split_line{1})]; % Breakpoints1 for the Lookup Table
tbl = [tbl; str2double(split_line{2})];
if ~eq(length(x2), length(x1))
intrpl_y = repelem(x2(end), (length(x1) – length(x2)))’;
x2 = [x2; intrpl_y]; % Breakpoints2 for the Lookup Table
end
if ~eq(length(x3), length(x1))
intrpl_z = repelem(x3(end), (length(x1) – length(x3)))’;
x3 = [x3; intrpl_z]; % Breakpoints3 for the Lookup Table
end
end
end
end
end
arr = [x1, x2, x3, tbl]; % Creating an array of all the data
a2tbl = array2table(arr, ‘VariableNames’, {‘X_axis’, ‘Y_axis’, ‘Z_axis’, ‘Tabledata’}); % Converting array2table
z = sort(unique(x3)); y = sort(unique(x2)); x = sort(unique(x1)); % Sorting of the data
% Sorting the data in ascending order and assing the NAN values to the missing MAPS
for k = 1:length(x)
xx = x(k);
for l = 1:length(y)
yy = y(l);
for m = 1:length(z)
zz = z(m);
table_indxed = a2tbl(a2tbl.X_axis == xx & a2tbl.Y_axis == yy & a2tbl.Z_axis == zz, :);
if isempty(table_indxed)
table_indxed = table(xx, yy, zz, NaN, ‘VariableNames’, …
{‘X_axis’, ‘Y_axis’, ‘Z_axis’, ‘Tabledata’});
end
if ~exist(‘manpltd_tbl’, ‘var’)
manpltd_tbl = table_indxed;
else
manpltd_tbl = [manpltd_tbl; table_indxed];
end
end
end
end
% Filling the missing MAPS with the nearest values of the MAPS
manpltd_tbl.Tabledata = fillmissing(manpltd_tbl.Tabledata, ‘nearest’);
% nanLocations = isnan(manpltd_tbl.Tabledata);
% nanLinearIndexes = find(nanLocations);
% nonNanLinearIndexes = setdiff(1:numel(manpltd_tbl.Tabledata), nanLinearIndexes);
% Filling the missing MAPS with the nearest values of the MAPS
LUT.BP(1).Breakpoint = unique(manpltd_tbl.X_axis);
LUT.BP(2).Breakpoint = unique(manpltd_tbl.Y_axis);
LUT.BP(3).Breakpoint = unique(manpltd_tbl.Z_axis);
LUT.BP(1).Lenth = length(unique(manpltd_tbl.X_axis));
LUT.BP(2).Lenth = length(unique(manpltd_tbl.Y_axis));
LUT.BP(3).Lenth = length(unique(manpltd_tbl.Z_axis));
LUT.Table_data = reshape(manpltd_tbl.Tabledata, LUT.BP(:).Lenth);
case ‘XY’
% For XY AMETable —> 1D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(delimited_file_data{i});
if ~isnan(str2double(split_line{2}))
x = [x; split_line{2}];
y = [y; split_line{3}];
z = [z; split_line{4}];
end
end
end
LUT.BP(1).Breakpoint = x;
LUT.BP(2).Breakpoint = y;
LUT.Table_data = z;
otherwise
% For {2D, 3D…. 8D] AMETable —> 4D Lookup Table
LUT_Dimns = str2double(deblank(extractBefore(LUT_Dimns, ‘D’)));
n = 1;
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line(~cellfun(‘isempty’,split_line))))
if (n <= LUT_Dimns)
if ~isfield(LUT, ‘BP’)
k = i;
end
for j = 1:LUT_Dimns
LUT.BP(n).Lenth = str2double(split_line(~cellfun(‘isempty’,split_line)));
split_BP = strsplit(delimited_file_data{i+LUT_Dimns});
LUT.BP(n).Breakpoint = str2double(split_BP(~cellfun(‘isempty’,split_BP)));
break
end
n = n+1;
elseif i >= ( k + 2*LUT_Dimns)
line_table_data = str2double(split_line(~cellfun(‘isempty’,split_line)));
tbl = [tbl; line_table_data];
end
end
end
end
for j = 1:size(tbl, 1)
if j == 1
conv_table_dta = transpose(tbl(j, :));
else
TransCol = transpose(tbl(j, :));
conv_table_dta = [conv_table_dta; TransCol];
end
end
LUT.Table_data = reshape(conv_table_dta, LUT.BP(:).Lenth);
end
end I want to convert AMESim software supported AMETable data (.data files) to Simulink Lookup tables suppoerted data. When I tried with the below code and applie to the N-D lookup table in simulink I am having the following error.
% ———————————————–
% This script is developed to convert the AMESim Looukp table to Simulink
% supported format.
% It supports the AMESim [ 1D, {2D, …. 8D}, T1D(Multi 1D),
% T3D (Multi M1D), XY tables conversion to Simulink format
% ———————————————–
% Input = "filename.data"
% Output = LUT —> is a structure
% —> LUT.BP.Breakpoint holds the Breakpoints data
% —> LUT.BP.Lenth holds the number of elements in each breakpoint
% —> LUT.BP.Table_data holds the table data
fname = uigetfile({‘*.data’;’*.txt’}, ‘Select the .data file for conversion’); % To get the file from the user
if fname == 0
error(‘User not selected the file for conversion’);
else
LUT = AMETable_2_Simulink(fname); % Function call to the conversion function
end
function LUT = AMETable_2_Simulink(fname)
fid = fopen(fname, "r", "ieee-le", "UTF-8");
file_data = fscanf(fid, ‘%c’);
delimited_file_data = strsplit(file_data, {‘n’})’; % Splitting the file data by using new line delimiter
fclose(fid);
LUT_Dimns = strtrim(extractAfter(delimited_file_data{1},"format:")); % Finding the Table format type
% Declaring the empty arrays
x_ele = []; y_ele = []; z_ele = []; T_ele = [];
x1 = []; x2 = []; x3 = []; tbl = [];
x = []; y = []; z = []; tbl_data = [];
LUT = struct;
switch LUT_Dimns
case ‘1D’
% For 1D AMETable —> 1D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i}) % Checking if it not an empty line
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line{1})) %
x = [x; split_line(1)]; % Breakpoints for the Lookup Table
tbl = [tbl; split_line(2)]; % Table for the Lookup Table
end
end
end
LUT.BP.Breakpoint = str2double(x)’;
LUT.Table_data = str2double(tbl)’;
case ‘T1D’
% For T1D AMETable —> 2D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line{1}))
if length(split_line{2}) <= 3
x2 = [x2; str2double(split_line{1})]; % Breakpoints2 for the Lookup Table
else
x1 = [x1; str2double(split_line{1})]; % Breakpoints1 for the Lookup Table
tbl = [tbl; str2double(split_line{2})]; % Table for the Lookup Table
if ~eq(length(x2), length(x1))
intrpl_y = repelem(x2(end), (length(x1) – length(x2)))’;
x2 = [x2; intrpl_y]; % Breakpoints2 for the Lookup Table
end
end
end
end
end
arr = [x1, x2, tbl]; % Creating an array of all the data
a2tbl = array2table(arr, ‘VariableNames’, {‘X_axis’, ‘Y_axis’, ‘Tabledata’}); % Converting array2table
y = sort(unique(x2));
x = sort(unique(x1));
% Sorting the data in ascending order and assing the NAN values to the missing MAPS
for k = 1:length(x)
xx = x(k);
for l = 1:length(y)
yy = y(l);
table_indxed = a2tbl(a2tbl.X_axis == xx & a2tbl.Y_axis == yy, :);
if isempty(table_indxed)
table_indxed = table(xx, yy, NaN, ‘VariableNames’, …
{‘X_axis’, ‘Y_axis’, ‘Tabledata’});
end
if ~exist(‘manpltd_tbl’, ‘var’)
manpltd_tbl = table_indxed;
else
manpltd_tbl = [manpltd_tbl; table_indxed];
end
end
end
% Filling the missing MAPS with the nearest values of the MAPS
manpltd_tbl.Tabledata = fillmissing(manpltd_tbl.Tabledata, ‘nearest’);
% Asigning the Breakpoints & Table_data to the Structure
LUT.BP(1).Breakpoint = unique(manpltd_tbl.X_axis);
LUT.BP(2).Breakpoint = unique(manpltd_tbl.Y_axis);
LUT.BP(1).Lenth = length(unique(manpltd_tbl.X_axis));
LUT.BP(2).Lenth = length(unique(manpltd_tbl.Y_axis));
LUT.Table_data = reshape(manpltd_tbl.Tabledata, LUT.BP(:).Lenth);
case ‘T3D’
% For T3D AMETable —> 3D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line{1}))
if length(split_line{2}) <= 3
next_split_line = strsplit(strtrim(delimited_file_data{i + 1}));
if length(next_split_line{2}) <= 3
x3 = [x3; str2double(split_line{1})]; % Breakpoints3 for the Lookup Table
else
x2 = [x2; str2double(split_line{1})]; % Breakpoints2 for the Lookup Table
end
else
x1 = [x1; str2double(split_line{1})]; % Breakpoints1 for the Lookup Table
tbl = [tbl; str2double(split_line{2})];
if ~eq(length(x2), length(x1))
intrpl_y = repelem(x2(end), (length(x1) – length(x2)))’;
x2 = [x2; intrpl_y]; % Breakpoints2 for the Lookup Table
end
if ~eq(length(x3), length(x1))
intrpl_z = repelem(x3(end), (length(x1) – length(x3)))’;
x3 = [x3; intrpl_z]; % Breakpoints3 for the Lookup Table
end
end
end
end
end
arr = [x1, x2, x3, tbl]; % Creating an array of all the data
a2tbl = array2table(arr, ‘VariableNames’, {‘X_axis’, ‘Y_axis’, ‘Z_axis’, ‘Tabledata’}); % Converting array2table
z = sort(unique(x3)); y = sort(unique(x2)); x = sort(unique(x1)); % Sorting of the data
% Sorting the data in ascending order and assing the NAN values to the missing MAPS
for k = 1:length(x)
xx = x(k);
for l = 1:length(y)
yy = y(l);
for m = 1:length(z)
zz = z(m);
table_indxed = a2tbl(a2tbl.X_axis == xx & a2tbl.Y_axis == yy & a2tbl.Z_axis == zz, :);
if isempty(table_indxed)
table_indxed = table(xx, yy, zz, NaN, ‘VariableNames’, …
{‘X_axis’, ‘Y_axis’, ‘Z_axis’, ‘Tabledata’});
end
if ~exist(‘manpltd_tbl’, ‘var’)
manpltd_tbl = table_indxed;
else
manpltd_tbl = [manpltd_tbl; table_indxed];
end
end
end
end
% Filling the missing MAPS with the nearest values of the MAPS
manpltd_tbl.Tabledata = fillmissing(manpltd_tbl.Tabledata, ‘nearest’);
% nanLocations = isnan(manpltd_tbl.Tabledata);
% nanLinearIndexes = find(nanLocations);
% nonNanLinearIndexes = setdiff(1:numel(manpltd_tbl.Tabledata), nanLinearIndexes);
% Filling the missing MAPS with the nearest values of the MAPS
LUT.BP(1).Breakpoint = unique(manpltd_tbl.X_axis);
LUT.BP(2).Breakpoint = unique(manpltd_tbl.Y_axis);
LUT.BP(3).Breakpoint = unique(manpltd_tbl.Z_axis);
LUT.BP(1).Lenth = length(unique(manpltd_tbl.X_axis));
LUT.BP(2).Lenth = length(unique(manpltd_tbl.Y_axis));
LUT.BP(3).Lenth = length(unique(manpltd_tbl.Z_axis));
LUT.Table_data = reshape(manpltd_tbl.Tabledata, LUT.BP(:).Lenth);
case ‘XY’
% For XY AMETable —> 1D Lookup Table
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(delimited_file_data{i});
if ~isnan(str2double(split_line{2}))
x = [x; split_line{2}];
y = [y; split_line{3}];
z = [z; split_line{4}];
end
end
end
LUT.BP(1).Breakpoint = x;
LUT.BP(2).Breakpoint = y;
LUT.Table_data = z;
otherwise
% For {2D, 3D…. 8D] AMETable —> 4D Lookup Table
LUT_Dimns = str2double(deblank(extractBefore(LUT_Dimns, ‘D’)));
n = 1;
for i = 2:length(delimited_file_data)
if ~isempty(delimited_file_data{i})
split_line = strsplit(strtrim(delimited_file_data{i}));
if ~isnan(str2double(split_line(~cellfun(‘isempty’,split_line))))
if (n <= LUT_Dimns)
if ~isfield(LUT, ‘BP’)
k = i;
end
for j = 1:LUT_Dimns
LUT.BP(n).Lenth = str2double(split_line(~cellfun(‘isempty’,split_line)));
split_BP = strsplit(delimited_file_data{i+LUT_Dimns});
LUT.BP(n).Breakpoint = str2double(split_BP(~cellfun(‘isempty’,split_BP)));
break
end
n = n+1;
elseif i >= ( k + 2*LUT_Dimns)
line_table_data = str2double(split_line(~cellfun(‘isempty’,split_line)));
tbl = [tbl; line_table_data];
end
end
end
end
for j = 1:size(tbl, 1)
if j == 1
conv_table_dta = transpose(tbl(j, :));
else
TransCol = transpose(tbl(j, :));
conv_table_dta = [conv_table_dta; TransCol];
end
end
LUT.Table_data = reshape(conv_table_dta, LUT.BP(:).Lenth);
end
end siemens – amesim, amesim, co-simulation, data exchange MATLAB Answers — New Questions
Locate peaks of an fft without using ‘findpeaks’
Hi everyone .. I have some data from an fft and need to locate the peaks .I know the ‘ findpeaks’ function performs this but I don’t have the license to signal processing toolHi everyone .. I have some data from an fft and need to locate the peaks .I know the ‘ findpeaks’ function performs this but I don’t have the license to signal processing tool Hi everyone .. I have some data from an fft and need to locate the peaks .I know the ‘ findpeaks’ function performs this but I don’t have the license to signal processing tool signal processing, fft MATLAB Answers — New Questions
openDRIVE(.xodr) 파일을 로드러너에 Import 시 도로 형상 깨짐
openDRIVE(.xodr) 파일을 로드러너에 import 시 도로 형상이 깨집니다.
테스트 겸 직접 제작한 도로를 .xodr 포맷으로 추출 후 해당 파일을 로드러너에 올려도 상기 첨부 사진과 같이 도로 형상이 깨지는데 해결 방법이 있을까요.
When I import an openDRIVE (.xodr) file into my simulation software, the road geometry appears distorted. Even when I export a road that I created myself in .xodr format and load it into the simulation software, the road shape gets corrupted as shown in the attached images. Is there a solution to this issue?openDRIVE(.xodr) 파일을 로드러너에 import 시 도로 형상이 깨집니다.
테스트 겸 직접 제작한 도로를 .xodr 포맷으로 추출 후 해당 파일을 로드러너에 올려도 상기 첨부 사진과 같이 도로 형상이 깨지는데 해결 방법이 있을까요.
When I import an openDRIVE (.xodr) file into my simulation software, the road geometry appears distorted. Even when I export a road that I created myself in .xodr format and load it into the simulation software, the road shape gets corrupted as shown in the attached images. Is there a solution to this issue? openDRIVE(.xodr) 파일을 로드러너에 import 시 도로 형상이 깨집니다.
테스트 겸 직접 제작한 도로를 .xodr 포맷으로 추출 후 해당 파일을 로드러너에 올려도 상기 첨부 사진과 같이 도로 형상이 깨지는데 해결 방법이 있을까요.
When I import an openDRIVE (.xodr) file into my simulation software, the road geometry appears distorted. Even when I export a road that I created myself in .xodr format and load it into the simulation software, the road shape gets corrupted as shown in the attached images. Is there a solution to this issue? xodr, import MATLAB Answers — New Questions
Getting error while using .m files in MATLAB function block in simulink.
Hello,
I am currently working on creating a custom RMS block within MATLAB’s Simulink environment.
My goal is to replicate the functionality of the standard RMS block using a MATLAB function.
I have developed an .m file (attached) that calculates the RMS value. However, I am encountering difficulties in implementing this code within the Simulink Function block.
Could anyone assist me in resolving this issue?
thank you
-Madhusudan reddyHello,
I am currently working on creating a custom RMS block within MATLAB’s Simulink environment.
My goal is to replicate the functionality of the standard RMS block using a MATLAB function.
I have developed an .m file (attached) that calculates the RMS value. However, I am encountering difficulties in implementing this code within the Simulink Function block.
Could anyone assist me in resolving this issue?
thank you
-Madhusudan reddy Hello,
I am currently working on creating a custom RMS block within MATLAB’s Simulink environment.
My goal is to replicate the functionality of the standard RMS block using a MATLAB function.
I have developed an .m file (attached) that calculates the RMS value. However, I am encountering difficulties in implementing this code within the Simulink Function block.
Could anyone assist me in resolving this issue?
thank you
-Madhusudan reddy matlab, hdl, rms, matlab function, ni fpga MATLAB Answers — New Questions
3-factor anova
Hello,
I would like to ask how to perform 3-factor anova (2-level noise, 3-level device, 9-level activity) on ECG signal data as well how to prepare related charts?Hello,
I would like to ask how to perform 3-factor anova (2-level noise, 3-level device, 9-level activity) on ECG signal data as well how to prepare related charts? Hello,
I would like to ask how to perform 3-factor anova (2-level noise, 3-level device, 9-level activity) on ECG signal data as well how to prepare related charts? anova MATLAB Answers — New Questions
when i package app and simulink file,why have this error
function startupFcn(app)
start_simulink
end
% Button pushed function: Button
function ButtonPushed(app, event)
%创建模型输入
simInp = Simulink.SimulationInput(‘untitled’);
simInp = simInp.setVariable(‘a’,app.EditField.Value);
simInp = simulink.compiler.configureForDeployment(simInp);
%执行并取出结果
simOut = sim(simInp);
b=simOut.b;
app.EditField_2.Value=b;
end
this is my code in app,and the package error is
Preparing Runtime…
mcc -o app1 -W ‘WinMain:app1,version=1.0’ -T link:exe -d C:UsersadminDesktop322newapp1for_testing -v C:UsersadminDesktop322newapp1.mlapp -a C:UsersadminDesktop322newtest.m -a C:UsersadminDesktop322newuntitled.slx -r D:matlab2023toolboxcompilerpackagingResourcesdefault_icon.ico
Compiler version: 8.6 (R2023a)
Analyzing file dependencies.
Unable to build Simulink Rapid Accelerator target.
mcc failurefunction startupFcn(app)
start_simulink
end
% Button pushed function: Button
function ButtonPushed(app, event)
%创建模型输入
simInp = Simulink.SimulationInput(‘untitled’);
simInp = simInp.setVariable(‘a’,app.EditField.Value);
simInp = simulink.compiler.configureForDeployment(simInp);
%执行并取出结果
simOut = sim(simInp);
b=simOut.b;
app.EditField_2.Value=b;
end
this is my code in app,and the package error is
Preparing Runtime…
mcc -o app1 -W ‘WinMain:app1,version=1.0’ -T link:exe -d C:UsersadminDesktop322newapp1for_testing -v C:UsersadminDesktop322newapp1.mlapp -a C:UsersadminDesktop322newtest.m -a C:UsersadminDesktop322newuntitled.slx -r D:matlab2023toolboxcompilerpackagingResourcesdefault_icon.ico
Compiler version: 8.6 (R2023a)
Analyzing file dependencies.
Unable to build Simulink Rapid Accelerator target.
mcc failure function startupFcn(app)
start_simulink
end
% Button pushed function: Button
function ButtonPushed(app, event)
%创建模型输入
simInp = Simulink.SimulationInput(‘untitled’);
simInp = simInp.setVariable(‘a’,app.EditField.Value);
simInp = simulink.compiler.configureForDeployment(simInp);
%执行并取出结果
simOut = sim(simInp);
b=simOut.b;
app.EditField_2.Value=b;
end
this is my code in app,and the package error is
Preparing Runtime…
mcc -o app1 -W ‘WinMain:app1,version=1.0’ -T link:exe -d C:UsersadminDesktop322newapp1for_testing -v C:UsersadminDesktop322newapp1.mlapp -a C:UsersadminDesktop322newtest.m -a C:UsersadminDesktop322newuntitled.slx -r D:matlab2023toolboxcompilerpackagingResourcesdefault_icon.ico
Compiler version: 8.6 (R2023a)
Analyzing file dependencies.
Unable to build Simulink Rapid Accelerator target.
mcc failure appdesigner, simulink MATLAB Answers — New Questions
Extract features from training images (Matlab – Computer Vision)
Hello. Thanks for reading my question. Sorry if it’s an easy question but I’m new in Matlab and Computer Vision. I’m trying to extract features from training images. I need to use histogram of color, histogram of gradient, SIFT-like features and compare their performance. I’m lost and have spent days to find a good way to use. How would you extract features in this example? I have put %Start and %End where I need to do that.
A written code would be greatly appreciated.
% Step-1: Load training and test data using imageSet.
imageDir = fullfile(‘./data’);
% imageSet recursively scans the directory tree containing the images.
flowerImageSet = imageSet(imageDir, ‘recursive’);
%% step-2: Partition the data set into a training set and a test set.
tmparr=randperm(80);
arrTrainID=tmparr(1:50); %training ID;
arrTestID=tmparr(51:end);% testing ID;
%% Step-3: Train the classifier using features extracted from the training set.
% Step 3.1 Extract features from training images
trainingFeatures = [];
trainingLabels = [];
featureSize =128;
for flower = 1:numel(flowerImageSet)
numImages = numel(arrTrainID);
features = zeros(numImages, featureSize);
for i = 1:numImages
img = rgb2gray(read(flowerImageSet(flower), arrTrainID(i)));
%START
features(i, 🙂 = rand(1,featureSize);
%END
end
% Use the imageSet Description as the training labels.
labels = repmat(flowerImageSet(flower).Description, numImages, 1);
trainingFeatures = [trainingFeatures; features];
trainingLabels = [trainingLabels; labels ];
end
%%
% Step 3.2, train a classifier using the extracted features.
classifier = fitcecoc(trainingFeatures, trainingLabels);
%% Step 4: Evaluate the Flower Classifier
testFeatures=[];
testLabels=[];
% Step 4.1: Loop over the testing images and extract features from each image.
for flower = 1:numel(flowerImageSet)
numImages = numel(arrTestID); %
features = zeros(numImages, featureSize);
for i = 1:numImages
img = rgb2gray(read(flowerImageSet(flower), arrTestID(i)));
%Start
features(i, 🙂 = rand(1,featureSize);
%End
end
% Use the imageSet Description as the training labels.
labels = repmat(flowerImageSet(flower).Description, numImages, 1);
testFeatures = [testFeatures; features];
testLabels = [testLabels; labels ];
end
% Step 4.2: Make class predictions using the test features.
predictedLabels = predict(classifier, testFeatures);
% Step 4.3: Tabulate the results using a confusion matrix.
confMat = confusionmat(testLabels, predictedLabels);
% Step 4.4: calculate accuracy
fprintf(‘accuracy=%f’,sum(diag(confMat))/sum(confMat(:)));Hello. Thanks for reading my question. Sorry if it’s an easy question but I’m new in Matlab and Computer Vision. I’m trying to extract features from training images. I need to use histogram of color, histogram of gradient, SIFT-like features and compare their performance. I’m lost and have spent days to find a good way to use. How would you extract features in this example? I have put %Start and %End where I need to do that.
A written code would be greatly appreciated.
% Step-1: Load training and test data using imageSet.
imageDir = fullfile(‘./data’);
% imageSet recursively scans the directory tree containing the images.
flowerImageSet = imageSet(imageDir, ‘recursive’);
%% step-2: Partition the data set into a training set and a test set.
tmparr=randperm(80);
arrTrainID=tmparr(1:50); %training ID;
arrTestID=tmparr(51:end);% testing ID;
%% Step-3: Train the classifier using features extracted from the training set.
% Step 3.1 Extract features from training images
trainingFeatures = [];
trainingLabels = [];
featureSize =128;
for flower = 1:numel(flowerImageSet)
numImages = numel(arrTrainID);
features = zeros(numImages, featureSize);
for i = 1:numImages
img = rgb2gray(read(flowerImageSet(flower), arrTrainID(i)));
%START
features(i, 🙂 = rand(1,featureSize);
%END
end
% Use the imageSet Description as the training labels.
labels = repmat(flowerImageSet(flower).Description, numImages, 1);
trainingFeatures = [trainingFeatures; features];
trainingLabels = [trainingLabels; labels ];
end
%%
% Step 3.2, train a classifier using the extracted features.
classifier = fitcecoc(trainingFeatures, trainingLabels);
%% Step 4: Evaluate the Flower Classifier
testFeatures=[];
testLabels=[];
% Step 4.1: Loop over the testing images and extract features from each image.
for flower = 1:numel(flowerImageSet)
numImages = numel(arrTestID); %
features = zeros(numImages, featureSize);
for i = 1:numImages
img = rgb2gray(read(flowerImageSet(flower), arrTestID(i)));
%Start
features(i, 🙂 = rand(1,featureSize);
%End
end
% Use the imageSet Description as the training labels.
labels = repmat(flowerImageSet(flower).Description, numImages, 1);
testFeatures = [testFeatures; features];
testLabels = [testLabels; labels ];
end
% Step 4.2: Make class predictions using the test features.
predictedLabels = predict(classifier, testFeatures);
% Step 4.3: Tabulate the results using a confusion matrix.
confMat = confusionmat(testLabels, predictedLabels);
% Step 4.4: calculate accuracy
fprintf(‘accuracy=%f’,sum(diag(confMat))/sum(confMat(:))); Hello. Thanks for reading my question. Sorry if it’s an easy question but I’m new in Matlab and Computer Vision. I’m trying to extract features from training images. I need to use histogram of color, histogram of gradient, SIFT-like features and compare their performance. I’m lost and have spent days to find a good way to use. How would you extract features in this example? I have put %Start and %End where I need to do that.
A written code would be greatly appreciated.
% Step-1: Load training and test data using imageSet.
imageDir = fullfile(‘./data’);
% imageSet recursively scans the directory tree containing the images.
flowerImageSet = imageSet(imageDir, ‘recursive’);
%% step-2: Partition the data set into a training set and a test set.
tmparr=randperm(80);
arrTrainID=tmparr(1:50); %training ID;
arrTestID=tmparr(51:end);% testing ID;
%% Step-3: Train the classifier using features extracted from the training set.
% Step 3.1 Extract features from training images
trainingFeatures = [];
trainingLabels = [];
featureSize =128;
for flower = 1:numel(flowerImageSet)
numImages = numel(arrTrainID);
features = zeros(numImages, featureSize);
for i = 1:numImages
img = rgb2gray(read(flowerImageSet(flower), arrTrainID(i)));
%START
features(i, 🙂 = rand(1,featureSize);
%END
end
% Use the imageSet Description as the training labels.
labels = repmat(flowerImageSet(flower).Description, numImages, 1);
trainingFeatures = [trainingFeatures; features];
trainingLabels = [trainingLabels; labels ];
end
%%
% Step 3.2, train a classifier using the extracted features.
classifier = fitcecoc(trainingFeatures, trainingLabels);
%% Step 4: Evaluate the Flower Classifier
testFeatures=[];
testLabels=[];
% Step 4.1: Loop over the testing images and extract features from each image.
for flower = 1:numel(flowerImageSet)
numImages = numel(arrTestID); %
features = zeros(numImages, featureSize);
for i = 1:numImages
img = rgb2gray(read(flowerImageSet(flower), arrTestID(i)));
%Start
features(i, 🙂 = rand(1,featureSize);
%End
end
% Use the imageSet Description as the training labels.
labels = repmat(flowerImageSet(flower).Description, numImages, 1);
testFeatures = [testFeatures; features];
testLabels = [testLabels; labels ];
end
% Step 4.2: Make class predictions using the test features.
predictedLabels = predict(classifier, testFeatures);
% Step 4.3: Tabulate the results using a confusion matrix.
confMat = confusionmat(testLabels, predictedLabels);
% Step 4.4: calculate accuracy
fprintf(‘accuracy=%f’,sum(diag(confMat))/sum(confMat(:))); computer vision, computer science MATLAB Answers — New Questions
How to Automatically detect MicrosoftVisual C++ 2019 v16.0 | nmake (64-bit Windows) toolchain in code generation setting ?
Hi ,
I have set setting for the toolchain "Automatically locate an installed toolchain" so it is selecting MINGW64 | gmake (64-bit windows). Instead of this i want it should detect "MicrosoftVisual C++ 2019 v16.0 | nmake (64-bit Windows)" automatically. I have already installed Microsoft visual c++ 2015-2019 redistributable (x64). check the attached image.
Note: I do not wanted to change " "Automatically locate an installed toolchain", it should detect automatically "MicrosoftVisual C++ 2019 v16.0 | nmake (64-bit Windows)"
Please help on this topic.Hi ,
I have set setting for the toolchain "Automatically locate an installed toolchain" so it is selecting MINGW64 | gmake (64-bit windows). Instead of this i want it should detect "MicrosoftVisual C++ 2019 v16.0 | nmake (64-bit Windows)" automatically. I have already installed Microsoft visual c++ 2015-2019 redistributable (x64). check the attached image.
Note: I do not wanted to change " "Automatically locate an installed toolchain", it should detect automatically "MicrosoftVisual C++ 2019 v16.0 | nmake (64-bit Windows)"
Please help on this topic. Hi ,
I have set setting for the toolchain "Automatically locate an installed toolchain" so it is selecting MINGW64 | gmake (64-bit windows). Instead of this i want it should detect "MicrosoftVisual C++ 2019 v16.0 | nmake (64-bit Windows)" automatically. I have already installed Microsoft visual c++ 2015-2019 redistributable (x64). check the attached image.
Note: I do not wanted to change " "Automatically locate an installed toolchain", it should detect automatically "MicrosoftVisual C++ 2019 v16.0 | nmake (64-bit Windows)"
Please help on this topic. embedded coder, simulink MATLAB Answers — New Questions
I am working on a simulation in Simscape involving a three-phase rectifier fed by a three-phase synchronous machine (alternator with round rotor).
I have successfully modeled both components, but I am facing a significant issue. When I replace the three-phase voltage source with the alternator, the input voltage to the three-phase rectifier becomes nearly zero, despite the alternator producing a stable three-phase voltage.
Here are the details of my setup:
Rectifier Configuration:
Using a Universal Bridge block in Simulink and a Converter (Three-Phase) block in Simscape.
Parameters for Universal Bridge:
Number of bridge arms: 3
Snubber resistance Rs: 1e5 Ohms
Snubber capacitance Cs: inf
Power electronic device: IGBT / Diodes
Ron: 1e-3 Ohms
Forward voltages [Device Vf(V), Diode Vfd(V)]: [0 0]
Parameters for Converter (Three-Phase):
Forward voltage, Vf: 0.00000001 V
On-state resistance: 0.001 Ohm
Off-state conductance: 1e-6 1/Ohm
Threshold voltage, Vth: 0.1 V
Integral protection diode: Diode with no dynamics
Forward voltage: 0.00000001 V
On resistance: 0.001 Ohm
Off conductance: 1e-5 1/Ohm
Snubber: RC snubber
Snubber capacitance: 1e-7 F
Snubber resistance: 1e5 Ohms
Alternator Parameters:
Three-phase synchronous machine with a round rotor.
Proper initialization and verified output: stable three-phase voltage and current.
Simulation Settings:
Solver: ode23t
Proper machine initialization.
Problem Description:
The output of the alternator is a good three-phase voltage and current when checked independently.
When the alternator is connected to the rectifier, the input voltage to the rectifier is distorted and significantly diminished.
No connection issues were found, and the simulation settings were adjusted, including changing the solver to ode23t, but the problem persists.
Questions:
What could be causing the input voltage to the rectifier to be nearly zero when using the three-phase synchronous machine as the source?
Are there specific snubber values or configurations that could resolve this issue?
Could there be any interaction or parameter mismatch between the alternator and the rectifier that I need to address?
What are the best practices for setting snubber parameters in such a setup?
Any insights or suggestions to resolve this issue would be greatly appreciated. Thank you for your help!I have successfully modeled both components, but I am facing a significant issue. When I replace the three-phase voltage source with the alternator, the input voltage to the three-phase rectifier becomes nearly zero, despite the alternator producing a stable three-phase voltage.
Here are the details of my setup:
Rectifier Configuration:
Using a Universal Bridge block in Simulink and a Converter (Three-Phase) block in Simscape.
Parameters for Universal Bridge:
Number of bridge arms: 3
Snubber resistance Rs: 1e5 Ohms
Snubber capacitance Cs: inf
Power electronic device: IGBT / Diodes
Ron: 1e-3 Ohms
Forward voltages [Device Vf(V), Diode Vfd(V)]: [0 0]
Parameters for Converter (Three-Phase):
Forward voltage, Vf: 0.00000001 V
On-state resistance: 0.001 Ohm
Off-state conductance: 1e-6 1/Ohm
Threshold voltage, Vth: 0.1 V
Integral protection diode: Diode with no dynamics
Forward voltage: 0.00000001 V
On resistance: 0.001 Ohm
Off conductance: 1e-5 1/Ohm
Snubber: RC snubber
Snubber capacitance: 1e-7 F
Snubber resistance: 1e5 Ohms
Alternator Parameters:
Three-phase synchronous machine with a round rotor.
Proper initialization and verified output: stable three-phase voltage and current.
Simulation Settings:
Solver: ode23t
Proper machine initialization.
Problem Description:
The output of the alternator is a good three-phase voltage and current when checked independently.
When the alternator is connected to the rectifier, the input voltage to the rectifier is distorted and significantly diminished.
No connection issues were found, and the simulation settings were adjusted, including changing the solver to ode23t, but the problem persists.
Questions:
What could be causing the input voltage to the rectifier to be nearly zero when using the three-phase synchronous machine as the source?
Are there specific snubber values or configurations that could resolve this issue?
Could there be any interaction or parameter mismatch between the alternator and the rectifier that I need to address?
What are the best practices for setting snubber parameters in such a setup?
Any insights or suggestions to resolve this issue would be greatly appreciated. Thank you for your help! I have successfully modeled both components, but I am facing a significant issue. When I replace the three-phase voltage source with the alternator, the input voltage to the three-phase rectifier becomes nearly zero, despite the alternator producing a stable three-phase voltage.
Here are the details of my setup:
Rectifier Configuration:
Using a Universal Bridge block in Simulink and a Converter (Three-Phase) block in Simscape.
Parameters for Universal Bridge:
Number of bridge arms: 3
Snubber resistance Rs: 1e5 Ohms
Snubber capacitance Cs: inf
Power electronic device: IGBT / Diodes
Ron: 1e-3 Ohms
Forward voltages [Device Vf(V), Diode Vfd(V)]: [0 0]
Parameters for Converter (Three-Phase):
Forward voltage, Vf: 0.00000001 V
On-state resistance: 0.001 Ohm
Off-state conductance: 1e-6 1/Ohm
Threshold voltage, Vth: 0.1 V
Integral protection diode: Diode with no dynamics
Forward voltage: 0.00000001 V
On resistance: 0.001 Ohm
Off conductance: 1e-5 1/Ohm
Snubber: RC snubber
Snubber capacitance: 1e-7 F
Snubber resistance: 1e5 Ohms
Alternator Parameters:
Three-phase synchronous machine with a round rotor.
Proper initialization and verified output: stable three-phase voltage and current.
Simulation Settings:
Solver: ode23t
Proper machine initialization.
Problem Description:
The output of the alternator is a good three-phase voltage and current when checked independently.
When the alternator is connected to the rectifier, the input voltage to the rectifier is distorted and significantly diminished.
No connection issues were found, and the simulation settings were adjusted, including changing the solver to ode23t, but the problem persists.
Questions:
What could be causing the input voltage to the rectifier to be nearly zero when using the three-phase synchronous machine as the source?
Are there specific snubber values or configurations that could resolve this issue?
Could there be any interaction or parameter mismatch between the alternator and the rectifier that I need to address?
What are the best practices for setting snubber parameters in such a setup?
Any insights or suggestions to resolve this issue would be greatly appreciated. Thank you for your help! i want to solve the problem please MATLAB Answers — New Questions
Different number of classes in training and testing data
Hello Everyone!
I am trying to develop a classifier for classification of different human activities i.e., standing, walking, sitting, laying in bed etc.
I have total of 6 classes in my dataset (concatenated all activities) and training multiple classifiers and also implementing K-fold cross validation during training.
I split my data into train and test set, train my classifier and then test my classifier and accuracies are pretty good (almost 95%). (I wont go into details of segmentation, feature extraction etc.)
The problem that I am facing right now is testing my classifier with completely new data. The following are some notable things about the new test data:
1) The new test data has 5 classes instead of 6.
2) The new test has continuous activities e.g., a person performing all 5 activities in quick succession without any break. Whereas, during training data, each activity was seprately recorded and then I concatenated all activities.
3) The accuracy that I am getting is around 70% (pretty bad) and also most of the misclassifications are being thrown into the class that is not in the new testing set e.g., class 6 is not present in new test set but when I check predictions, the classifier is saying (for major portion of activities) that it belongs to class 6.
I cannot reduce the number of classes in my training set because when I implement this in real-time, the subjects will perform all the 6 activities but ofcourse not all together and one by one e.g., in real-time, the subject will perform activity 1 (the classifier will classify it as 1) then activity 2 (the classifier will classify it as 2) and so on.
Can you people help me understand, which parameters I should observe to improve the accuracy of my classifier for the new test data? Because 70% is not acceptable to me. And any suggestions on the mistakes that you have seen here and can correct me and tell me the right path.
Thank you so much :)Hello Everyone!
I am trying to develop a classifier for classification of different human activities i.e., standing, walking, sitting, laying in bed etc.
I have total of 6 classes in my dataset (concatenated all activities) and training multiple classifiers and also implementing K-fold cross validation during training.
I split my data into train and test set, train my classifier and then test my classifier and accuracies are pretty good (almost 95%). (I wont go into details of segmentation, feature extraction etc.)
The problem that I am facing right now is testing my classifier with completely new data. The following are some notable things about the new test data:
1) The new test data has 5 classes instead of 6.
2) The new test has continuous activities e.g., a person performing all 5 activities in quick succession without any break. Whereas, during training data, each activity was seprately recorded and then I concatenated all activities.
3) The accuracy that I am getting is around 70% (pretty bad) and also most of the misclassifications are being thrown into the class that is not in the new testing set e.g., class 6 is not present in new test set but when I check predictions, the classifier is saying (for major portion of activities) that it belongs to class 6.
I cannot reduce the number of classes in my training set because when I implement this in real-time, the subjects will perform all the 6 activities but ofcourse not all together and one by one e.g., in real-time, the subject will perform activity 1 (the classifier will classify it as 1) then activity 2 (the classifier will classify it as 2) and so on.
Can you people help me understand, which parameters I should observe to improve the accuracy of my classifier for the new test data? Because 70% is not acceptable to me. And any suggestions on the mistakes that you have seen here and can correct me and tell me the right path.
Thank you so much 🙂 Hello Everyone!
I am trying to develop a classifier for classification of different human activities i.e., standing, walking, sitting, laying in bed etc.
I have total of 6 classes in my dataset (concatenated all activities) and training multiple classifiers and also implementing K-fold cross validation during training.
I split my data into train and test set, train my classifier and then test my classifier and accuracies are pretty good (almost 95%). (I wont go into details of segmentation, feature extraction etc.)
The problem that I am facing right now is testing my classifier with completely new data. The following are some notable things about the new test data:
1) The new test data has 5 classes instead of 6.
2) The new test has continuous activities e.g., a person performing all 5 activities in quick succession without any break. Whereas, during training data, each activity was seprately recorded and then I concatenated all activities.
3) The accuracy that I am getting is around 70% (pretty bad) and also most of the misclassifications are being thrown into the class that is not in the new testing set e.g., class 6 is not present in new test set but when I check predictions, the classifier is saying (for major portion of activities) that it belongs to class 6.
I cannot reduce the number of classes in my training set because when I implement this in real-time, the subjects will perform all the 6 activities but ofcourse not all together and one by one e.g., in real-time, the subject will perform activity 1 (the classifier will classify it as 1) then activity 2 (the classifier will classify it as 2) and so on.
Can you people help me understand, which parameters I should observe to improve the accuracy of my classifier for the new test data? Because 70% is not acceptable to me. And any suggestions on the mistakes that you have seen here and can correct me and tell me the right path.
Thank you so much 🙂 machine learning, activity recognition, training and testing classes, improve accuracy for real time MATLAB Answers — New Questions
How to convert signal data type by using function or code script
Is there a function or code script to change the signal data type of signal editor InputScenario in test harness like the following picture shows:Is there a function or code script to change the signal data type of signal editor InputScenario in test harness like the following picture shows: Is there a function or code script to change the signal data type of signal editor InputScenario in test harness like the following picture shows: signal editor MATLAB Answers — New Questions
Deforming sheet into conical structure
I am trying to deform a flat sheet into a conical structure using MATLAB. (Pls see the image below)
L = length of sheet; R= bigger radius; r = smaller radius
Here’s my approach:
First i create an upward ramp (as shown in the image above), with a displacement in z-direction given by:
u_1 = r/L * (pi-1) * x
2. Then curve the edges of rectangular sheet into the conical form, given by displacements:
3. Hence the net displacement of any point becomes u_1 + u_2.
I have written this as a matlab code:
for i=1:length(A)
A(i,2) = A(i,2) + (sqrt(2*A(i,3)*r – A(i,3)*A(i,3))-A(i,2))*(A(i,1)/L);
A(i,3) = A(i,3) + ((r/L)*(pi-1)*(A(i,1)) + (R-sqrt(R*R – A(i,2)*A(i,2))*(1-(A(i,1)/L))) + ((R-r)+ (2/pi)*A(i,2))*(A(i,1)/L));
A here is the matrix with initial coordinates of the flat sheet. Then using a for loop, i apply the u_1 + u_2 displacement, changing the y and z coordinates of the sheet.
However, after running the code, i get one side to be very nicely fitting the curvature of the cone, whereas on the other side, all the points coincide at one single point rather than forming a circular face. Please see the images below.
Original flat sheet
Curved conical sheet with the issue
Can someone please help me with this?I am trying to deform a flat sheet into a conical structure using MATLAB. (Pls see the image below)
L = length of sheet; R= bigger radius; r = smaller radius
Here’s my approach:
First i create an upward ramp (as shown in the image above), with a displacement in z-direction given by:
u_1 = r/L * (pi-1) * x
2. Then curve the edges of rectangular sheet into the conical form, given by displacements:
3. Hence the net displacement of any point becomes u_1 + u_2.
I have written this as a matlab code:
for i=1:length(A)
A(i,2) = A(i,2) + (sqrt(2*A(i,3)*r – A(i,3)*A(i,3))-A(i,2))*(A(i,1)/L);
A(i,3) = A(i,3) + ((r/L)*(pi-1)*(A(i,1)) + (R-sqrt(R*R – A(i,2)*A(i,2))*(1-(A(i,1)/L))) + ((R-r)+ (2/pi)*A(i,2))*(A(i,1)/L));
A here is the matrix with initial coordinates of the flat sheet. Then using a for loop, i apply the u_1 + u_2 displacement, changing the y and z coordinates of the sheet.
However, after running the code, i get one side to be very nicely fitting the curvature of the cone, whereas on the other side, all the points coincide at one single point rather than forming a circular face. Please see the images below.
Original flat sheet
Curved conical sheet with the issue
Can someone please help me with this? I am trying to deform a flat sheet into a conical structure using MATLAB. (Pls see the image below)
L = length of sheet; R= bigger radius; r = smaller radius
Here’s my approach:
First i create an upward ramp (as shown in the image above), with a displacement in z-direction given by:
u_1 = r/L * (pi-1) * x
2. Then curve the edges of rectangular sheet into the conical form, given by displacements:
3. Hence the net displacement of any point becomes u_1 + u_2.
I have written this as a matlab code:
for i=1:length(A)
A(i,2) = A(i,2) + (sqrt(2*A(i,3)*r – A(i,3)*A(i,3))-A(i,2))*(A(i,1)/L);
A(i,3) = A(i,3) + ((r/L)*(pi-1)*(A(i,1)) + (R-sqrt(R*R – A(i,2)*A(i,2))*(1-(A(i,1)/L))) + ((R-r)+ (2/pi)*A(i,2))*(A(i,1)/L));
A here is the matrix with initial coordinates of the flat sheet. Then using a for loop, i apply the u_1 + u_2 displacement, changing the y and z coordinates of the sheet.
However, after running the code, i get one side to be very nicely fitting the curvature of the cone, whereas on the other side, all the points coincide at one single point rather than forming a circular face. Please see the images below.
Original flat sheet
Curved conical sheet with the issue
Can someone please help me with this? deformation MATLAB Answers — New Questions
Excuse me, could you help me correctly name my Vcm1, Vcm2, Vcm3, Vcm4 in num2str?
grid on
xlabel(‘X’)
ylabel(‘Y’)
zlabel(‘Z’)
title([‘Tiempo de ‘,num2str(t(i)),’s’],’FontSize’,18)
axis([-60,60,-60,60,0,60])
legend(‘Eslabón 1′,’Eslabón 2′,’Eslabón 3′,’Eslabón 4′,’FontSize’,16)
dim = ([0.8 0.4 0.1 0.2])
annotation(‘textbox’,dim,’String’,num2str([‘Vcm1′,’Vcm2′,’Vcm3′,’Vcm4’]), ‘FontSize’;15) Invalid expression.
view(100,35)
pause(0.01)grid on
xlabel(‘X’)
ylabel(‘Y’)
zlabel(‘Z’)
title([‘Tiempo de ‘,num2str(t(i)),’s’],’FontSize’,18)
axis([-60,60,-60,60,0,60])
legend(‘Eslabón 1′,’Eslabón 2′,’Eslabón 3′,’Eslabón 4′,’FontSize’,16)
dim = ([0.8 0.4 0.1 0.2])
annotation(‘textbox’,dim,’String’,num2str([‘Vcm1′,’Vcm2′,’Vcm3′,’Vcm4’]), ‘FontSize’;15) Invalid expression.
view(100,35)
pause(0.01) grid on
xlabel(‘X’)
ylabel(‘Y’)
zlabel(‘Z’)
title([‘Tiempo de ‘,num2str(t(i)),’s’],’FontSize’,18)
axis([-60,60,-60,60,0,60])
legend(‘Eslabón 1′,’Eslabón 2′,’Eslabón 3′,’Eslabón 4′,’FontSize’,16)
dim = ([0.8 0.4 0.1 0.2])
annotation(‘textbox’,dim,’String’,num2str([‘Vcm1′,’Vcm2′,’Vcm3′,’Vcm4’]), ‘FontSize’;15) Invalid expression.
view(100,35)
pause(0.01) vcm, num2str MATLAB Answers — New Questions
Why use ‘delay’ for estimating a path for ANC?[simulink]
And, What is the difference between using delay and not using it when estimating a path for ANC?
The filter will already cause significant delay, so should I use it?
Thank you for your interest!
https://kr.mathworks.com/help/audio/ug/active-noise-control-with-simulink.htmlAnd, What is the difference between using delay and not using it when estimating a path for ANC?
The filter will already cause significant delay, so should I use it?
Thank you for your interest!
https://kr.mathworks.com/help/audio/ug/active-noise-control-with-simulink.html And, What is the difference between using delay and not using it when estimating a path for ANC?
The filter will already cause significant delay, so should I use it?
Thank you for your interest!
https://kr.mathworks.com/help/audio/ug/active-noise-control-with-simulink.html anc, fir, simulink MATLAB Answers — New Questions
Is it possible to utilize the sound recorded on ‘matlab mobile’ during simulink real time simulation?
I’m going to implement ANC for the location of my mobile phone through ‘Simulink’.
Mobile phones’ mic sensor will replace the role of microphones in this model.
https://kr.mathworks.com/help/audio/ug/active-noise-control-with-simulink.html?s_eid=PSM_15028
Is it possible? then what should i do?I’m going to implement ANC for the location of my mobile phone through ‘Simulink’.
Mobile phones’ mic sensor will replace the role of microphones in this model.
https://kr.mathworks.com/help/audio/ug/active-noise-control-with-simulink.html?s_eid=PSM_15028
Is it possible? then what should i do? I’m going to implement ANC for the location of my mobile phone through ‘Simulink’.
Mobile phones’ mic sensor will replace the role of microphones in this model.
https://kr.mathworks.com/help/audio/ug/active-noise-control-with-simulink.html?s_eid=PSM_15028
Is it possible? then what should i do? anc, mobile, simulink, real time MATLAB Answers — New Questions