Tag Archives: matlab
I am a biggner in matlab and i want to work on ANN for solving classification problem, how can i start?
0000 00 00 MATLAB Answers — New Questions
How to read numeric data with different number of columns
I would like to read in the numeric data below into 3 different arrays:
0 0.2 0.5 0.8 into "a_on_t"
4 10 into "Ri_on_t" and
2 5 10 into "2c_on_a"
I code just hard code these in, but it would be better to read them from a file. I was thinking of constructing the file like so:
% Header info describing file contents
% Rows correspond to:
% a / t
% Ri / t
% 2c / a
0 0.2 0.5 0.8
4 10
2 5 10
or, alternatively:
% Header info describing file contents
a_on_t 0 0.2 0.5 0.8
Ri_on_t 4 10
2c_on_a 2 5 10
I would like to be able to extract the names of the arrays in which to store the data from the file and, of course, to extract the numbers from the file. As I am using R2018a I don’t have access to the table reading functions. I have tried putting the data into a cell using textscan, but I just end up with a list (or 1D array) of numbers. I definitely need the numbers, I could hard code the names of the arrays for now.
fgetl might be a possibility, but then there is the difficulty of extracting the data from a cell and converting characters to numbers.
Am I missing something obvious? This seems much more difficult than it should be.
Thanks!I would like to read in the numeric data below into 3 different arrays:
0 0.2 0.5 0.8 into "a_on_t"
4 10 into "Ri_on_t" and
2 5 10 into "2c_on_a"
I code just hard code these in, but it would be better to read them from a file. I was thinking of constructing the file like so:
% Header info describing file contents
% Rows correspond to:
% a / t
% Ri / t
% 2c / a
0 0.2 0.5 0.8
4 10
2 5 10
or, alternatively:
% Header info describing file contents
a_on_t 0 0.2 0.5 0.8
Ri_on_t 4 10
2c_on_a 2 5 10
I would like to be able to extract the names of the arrays in which to store the data from the file and, of course, to extract the numbers from the file. As I am using R2018a I don’t have access to the table reading functions. I have tried putting the data into a cell using textscan, but I just end up with a list (or 1D array) of numbers. I definitely need the numbers, I could hard code the names of the arrays for now.
fgetl might be a possibility, but then there is the difficulty of extracting the data from a cell and converting characters to numbers.
Am I missing something obvious? This seems much more difficult than it should be.
Thanks! I would like to read in the numeric data below into 3 different arrays:
0 0.2 0.5 0.8 into "a_on_t"
4 10 into "Ri_on_t" and
2 5 10 into "2c_on_a"
I code just hard code these in, but it would be better to read them from a file. I was thinking of constructing the file like so:
% Header info describing file contents
% Rows correspond to:
% a / t
% Ri / t
% 2c / a
0 0.2 0.5 0.8
4 10
2 5 10
or, alternatively:
% Header info describing file contents
a_on_t 0 0.2 0.5 0.8
Ri_on_t 4 10
2c_on_a 2 5 10
I would like to be able to extract the names of the arrays in which to store the data from the file and, of course, to extract the numbers from the file. As I am using R2018a I don’t have access to the table reading functions. I have tried putting the data into a cell using textscan, but I just end up with a list (or 1D array) of numbers. I definitely need the numbers, I could hard code the names of the arrays for now.
fgetl might be a possibility, but then there is the difficulty of extracting the data from a cell and converting characters to numbers.
Am I missing something obvious? This seems much more difficult than it should be.
Thanks! read text file, variable length data, mixed data types MATLAB Answers — New Questions
Update graph (Graph Theory)?
Assuming I have a graph objects G = graph(s, t, weights) and I plotted it with plot(G, "XData", x, "YData", y); hold on;.
If during the program I (interactively) execute a callback function adding new nodes to G, I would like to update the plot.
I already know that I could just add the now and plot everything again, but is there a way to only plot the new nodes/edges?
Thanks in advance.Assuming I have a graph objects G = graph(s, t, weights) and I plotted it with plot(G, "XData", x, "YData", y); hold on;.
If during the program I (interactively) execute a callback function adding new nodes to G, I would like to update the plot.
I already know that I could just add the now and plot everything again, but is there a way to only plot the new nodes/edges?
Thanks in advance. Assuming I have a graph objects G = graph(s, t, weights) and I plotted it with plot(G, "XData", x, "YData", y); hold on;.
If during the program I (interactively) execute a callback function adding new nodes to G, I would like to update the plot.
I already know that I could just add the now and plot everything again, but is there a way to only plot the new nodes/edges?
Thanks in advance. graph, node, edges, graph theory, plot MATLAB Answers — New Questions
How to plot X-Y-Z triplets in a 2D polygon region boundary defined by X-Y pairs?
I want to plot numerical data with x, y, and z vectors, where x and y are the coordinates with values specified in z. The continuous relationship "z = f(x, y)" is unknown since the data is discrete. How do I produce a 2D contour plot of this data within the boundary of the X-Y plane specified by vectors x and y?I want to plot numerical data with x, y, and z vectors, where x and y are the coordinates with values specified in z. The continuous relationship "z = f(x, y)" is unknown since the data is discrete. How do I produce a 2D contour plot of this data within the boundary of the X-Y plane specified by vectors x and y? I want to plot numerical data with x, y, and z vectors, where x and y are the coordinates with values specified in z. The continuous relationship "z = f(x, y)" is unknown since the data is discrete. How do I produce a 2D contour plot of this data within the boundary of the X-Y plane specified by vectors x and y? scatter, 3d, plot, surf, surface, scatterplot, points, datapoints, contour, interpolate, extrapolate, distort MATLAB Answers — New Questions
“block choice ” button doesn’t seem on Simulink
ı m tryna prepare a battery simulation with simulink but when ı push right click on "battery-table based" , and then ı go simscape button, and ı just only see "log simulation data" . Have you any reccomend for this problem? It s probably an easy solution, but ı can’tı m tryna prepare a battery simulation with simulink but when ı push right click on "battery-table based" , and then ı go simscape button, and ı just only see "log simulation data" . Have you any reccomend for this problem? It s probably an easy solution, but ı can’t ı m tryna prepare a battery simulation with simulink but when ı push right click on "battery-table based" , and then ı go simscape button, and ı just only see "log simulation data" . Have you any reccomend for this problem? It s probably an easy solution, but ı can’t battery, simulink, simulation MATLAB Answers — New Questions
Understand values differences between smooth and smoothdata functions
Hi,
I’m working on rlowess smoothing and I was wondering why I observe output differences between smooth and smoothdata functions, despite the fact that they are supposed to be similar.
I wrote a small piece of code:
% Sample one-dimensional data
x = 1:100;
data = cos(2*pi*0.05*x+2*pi*rand) + 0.5*randn(1,100);
% Apply rlowess smoothing with smooth
smoothedData2 = smooth(data, 9, ‘rlowess’);
% Apply rlowess smoothing with smoothdata
smoothedData3 = smoothdata(data, ‘rlowess’, 9);
smoothedData2
smoothedData3
isequal(smoothedData2, smoothedData3)
% Plot the original and smoothed data
figure;
plot(x, data, ‘o’);
hold on;
plot(x, smoothedData2, ‘–‘);
plot(x, smoothedData3, ‘:’);
legend(‘Original Data’, ‘Smoothed Data 2’, ‘Smoothed Data 3’);
title(‘Comparison of Smoothing Methods’);
% Calculate the differences
diff2_3 = smoothedData2(:) – smoothedData3(:);
% Display the differences
disp(‘Difference between smoothedData2 and smoothedData3:’);
disp(diff2_3);
As you can see, the graph is similar for both cases, but the values are different.
I also tried to change the method to ‘lowess’, and the differences there are only on the first and last entries, so I’m guessing that the moving window isn’t calculated similarly in both cases (however, I can’t find a difference in the window calculation from the documentation here and here).
To sum up, my two questions are:
Is there a difference in window calculation between smooth and smoothdata for ‘lowess’ method
Apart from this difference, could there be another issue with the calculation of robust weights for example in ‘rlowess’ method.
Thank you!Hi,
I’m working on rlowess smoothing and I was wondering why I observe output differences between smooth and smoothdata functions, despite the fact that they are supposed to be similar.
I wrote a small piece of code:
% Sample one-dimensional data
x = 1:100;
data = cos(2*pi*0.05*x+2*pi*rand) + 0.5*randn(1,100);
% Apply rlowess smoothing with smooth
smoothedData2 = smooth(data, 9, ‘rlowess’);
% Apply rlowess smoothing with smoothdata
smoothedData3 = smoothdata(data, ‘rlowess’, 9);
smoothedData2
smoothedData3
isequal(smoothedData2, smoothedData3)
% Plot the original and smoothed data
figure;
plot(x, data, ‘o’);
hold on;
plot(x, smoothedData2, ‘–‘);
plot(x, smoothedData3, ‘:’);
legend(‘Original Data’, ‘Smoothed Data 2’, ‘Smoothed Data 3’);
title(‘Comparison of Smoothing Methods’);
% Calculate the differences
diff2_3 = smoothedData2(:) – smoothedData3(:);
% Display the differences
disp(‘Difference between smoothedData2 and smoothedData3:’);
disp(diff2_3);
As you can see, the graph is similar for both cases, but the values are different.
I also tried to change the method to ‘lowess’, and the differences there are only on the first and last entries, so I’m guessing that the moving window isn’t calculated similarly in both cases (however, I can’t find a difference in the window calculation from the documentation here and here).
To sum up, my two questions are:
Is there a difference in window calculation between smooth and smoothdata for ‘lowess’ method
Apart from this difference, could there be another issue with the calculation of robust weights for example in ‘rlowess’ method.
Thank you! Hi,
I’m working on rlowess smoothing and I was wondering why I observe output differences between smooth and smoothdata functions, despite the fact that they are supposed to be similar.
I wrote a small piece of code:
% Sample one-dimensional data
x = 1:100;
data = cos(2*pi*0.05*x+2*pi*rand) + 0.5*randn(1,100);
% Apply rlowess smoothing with smooth
smoothedData2 = smooth(data, 9, ‘rlowess’);
% Apply rlowess smoothing with smoothdata
smoothedData3 = smoothdata(data, ‘rlowess’, 9);
smoothedData2
smoothedData3
isequal(smoothedData2, smoothedData3)
% Plot the original and smoothed data
figure;
plot(x, data, ‘o’);
hold on;
plot(x, smoothedData2, ‘–‘);
plot(x, smoothedData3, ‘:’);
legend(‘Original Data’, ‘Smoothed Data 2’, ‘Smoothed Data 3’);
title(‘Comparison of Smoothing Methods’);
% Calculate the differences
diff2_3 = smoothedData2(:) – smoothedData3(:);
% Display the differences
disp(‘Difference between smoothedData2 and smoothedData3:’);
disp(diff2_3);
As you can see, the graph is similar for both cases, but the values are different.
I also tried to change the method to ‘lowess’, and the differences there are only on the first and last entries, so I’m guessing that the moving window isn’t calculated similarly in both cases (however, I can’t find a difference in the window calculation from the documentation here and here).
To sum up, my two questions are:
Is there a difference in window calculation between smooth and smoothdata for ‘lowess’ method
Apart from this difference, could there be another issue with the calculation of robust weights for example in ‘rlowess’ method.
Thank you! smooth, smoothdata MATLAB Answers — New Questions
How can I remove all rows from a matrix which contain NaN values?
How can I remove all rows from a matrix which contain NaN values?
For example:
>> A = [1, 2, 3; 4, NaN, 6; 7, 8, 9]
A =
1 2 3
4 NaN 6
7 8 9
In matrix A defined above, I would like to remove the second row, [4, NaN, 6].How can I remove all rows from a matrix which contain NaN values?
For example:
>> A = [1, 2, 3; 4, NaN, 6; 7, 8, 9]
A =
1 2 3
4 NaN 6
7 8 9
In matrix A defined above, I would like to remove the second row, [4, NaN, 6]. How can I remove all rows from a matrix which contain NaN values?
For example:
>> A = [1, 2, 3; 4, NaN, 6; 7, 8, 9]
A =
1 2 3
4 NaN 6
7 8 9
In matrix A defined above, I would like to remove the second row, [4, NaN, 6]. nan, matrix, isnan, removerowsnotnumber MATLAB Answers — New Questions
Transfer function model from block diagram
Hello, i am facing difficulties in translating the transfer function of the block diagram above into Matlab.
I do have the control systems toolbox.
for the system plant, I have
tf_1 = feedback(tf([1],[I_wh 0]),c_vis); % small loop with c_vis
tf_2 = series(tf([1/R],[L/R 1])*3/2*kT, tf_1) % series of tf_1 and motor tf
tf_system_plant = series(feedback(tf_2,ke),tf([J 0],1))
The upper two paths in the controller can be summarized as
tf_ctrl1 = parallel(tf(k_omega,[1 0]),tf(k_phi,[1 0 0]))
But I do not know how to include the feedback loop of the reaction torque and the feed forward component k_alpha.
Any help is appreciated!Hello, i am facing difficulties in translating the transfer function of the block diagram above into Matlab.
I do have the control systems toolbox.
for the system plant, I have
tf_1 = feedback(tf([1],[I_wh 0]),c_vis); % small loop with c_vis
tf_2 = series(tf([1/R],[L/R 1])*3/2*kT, tf_1) % series of tf_1 and motor tf
tf_system_plant = series(feedback(tf_2,ke),tf([J 0],1))
The upper two paths in the controller can be summarized as
tf_ctrl1 = parallel(tf(k_omega,[1 0]),tf(k_phi,[1 0 0]))
But I do not know how to include the feedback loop of the reaction torque and the feed forward component k_alpha.
Any help is appreciated! Hello, i am facing difficulties in translating the transfer function of the block diagram above into Matlab.
I do have the control systems toolbox.
for the system plant, I have
tf_1 = feedback(tf([1],[I_wh 0]),c_vis); % small loop with c_vis
tf_2 = series(tf([1/R],[L/R 1])*3/2*kT, tf_1) % series of tf_1 and motor tf
tf_system_plant = series(feedback(tf_2,ke),tf([J 0],1))
The upper two paths in the controller can be summarized as
tf_ctrl1 = parallel(tf(k_omega,[1 0]),tf(k_phi,[1 0 0]))
But I do not know how to include the feedback loop of the reaction torque and the feed forward component k_alpha.
Any help is appreciated! control, transfer function, blockdiagram, feedback loop, controller MATLAB Answers — New Questions
Issues with tables and writetable from data passed from uitable
Hello, I have an array in a uitable that I want to save to a csv file as well as the column headings. It seems out of the write options available (writecell,writematrix, writetable) – it is only writetable that allows this
Writetable appears to work, but when I open the CSV file it hasn’t and I can’t understand why
This is my code:
T=app.UITable;
data=T.Data;
C=array2table(data); % Create table format
T.ColumnName
C.Properties.VariableNames=T.ColumnName;
C.Properties.Description=’Scan Profile’;
C = addprop(C,{‘ScanStart’,’ScanTime’},{‘table’,’table’});
C.Properties.CustomProperties.ScanStart = app.scannow;
C.Properties.CustomProperties.ScanTime = app.scantime;
C.Properties
% C.Properties.VariableNames
writetable(C,savepath);
ReportMessage(app,’ Data Saved Using Writetable’);
And in the command window I get this, indicating all is O.K
ans =
6×1 cell array
{‘Idx’ }
{‘YPos(mm)’}
{‘Sep1’ }
{‘Sep2’ }
{‘<Sep>’ }
{‘dpixel’ }
ans =
TableProperties with properties:
Description: ‘Surface Profile’
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Idx’ ‘YPos(mm)’ ‘Sep1’ ‘Sep2’ ‘<Sep>’ ‘dpixel’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
Custom Properties (access using t.Properties.CustomProperties.<name>):
ScanStart: "29-Jan-2025 09:41:35"
ScanTime: ‘174.2796’
But then the file looks like this:
So no headings.
And When i also try to load via readtable – all of the description and custom propeerrties are not present
ans =
TableProperties with properties:
Description: ”
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Var1’ ‘Var2’ ‘Var3’ ‘Var4’ ‘Var5’ ‘Var6’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
CustomProperties: No custom properties are set.
Use addprop and rmprop to modify CustomProperties.Hello, I have an array in a uitable that I want to save to a csv file as well as the column headings. It seems out of the write options available (writecell,writematrix, writetable) – it is only writetable that allows this
Writetable appears to work, but when I open the CSV file it hasn’t and I can’t understand why
This is my code:
T=app.UITable;
data=T.Data;
C=array2table(data); % Create table format
T.ColumnName
C.Properties.VariableNames=T.ColumnName;
C.Properties.Description=’Scan Profile’;
C = addprop(C,{‘ScanStart’,’ScanTime’},{‘table’,’table’});
C.Properties.CustomProperties.ScanStart = app.scannow;
C.Properties.CustomProperties.ScanTime = app.scantime;
C.Properties
% C.Properties.VariableNames
writetable(C,savepath);
ReportMessage(app,’ Data Saved Using Writetable’);
And in the command window I get this, indicating all is O.K
ans =
6×1 cell array
{‘Idx’ }
{‘YPos(mm)’}
{‘Sep1’ }
{‘Sep2’ }
{‘<Sep>’ }
{‘dpixel’ }
ans =
TableProperties with properties:
Description: ‘Surface Profile’
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Idx’ ‘YPos(mm)’ ‘Sep1’ ‘Sep2’ ‘<Sep>’ ‘dpixel’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
Custom Properties (access using t.Properties.CustomProperties.<name>):
ScanStart: "29-Jan-2025 09:41:35"
ScanTime: ‘174.2796’
But then the file looks like this:
So no headings.
And When i also try to load via readtable – all of the description and custom propeerrties are not present
ans =
TableProperties with properties:
Description: ”
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Var1’ ‘Var2’ ‘Var3’ ‘Var4’ ‘Var5’ ‘Var6’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
CustomProperties: No custom properties are set.
Use addprop and rmprop to modify CustomProperties. Hello, I have an array in a uitable that I want to save to a csv file as well as the column headings. It seems out of the write options available (writecell,writematrix, writetable) – it is only writetable that allows this
Writetable appears to work, but when I open the CSV file it hasn’t and I can’t understand why
This is my code:
T=app.UITable;
data=T.Data;
C=array2table(data); % Create table format
T.ColumnName
C.Properties.VariableNames=T.ColumnName;
C.Properties.Description=’Scan Profile’;
C = addprop(C,{‘ScanStart’,’ScanTime’},{‘table’,’table’});
C.Properties.CustomProperties.ScanStart = app.scannow;
C.Properties.CustomProperties.ScanTime = app.scantime;
C.Properties
% C.Properties.VariableNames
writetable(C,savepath);
ReportMessage(app,’ Data Saved Using Writetable’);
And in the command window I get this, indicating all is O.K
ans =
6×1 cell array
{‘Idx’ }
{‘YPos(mm)’}
{‘Sep1’ }
{‘Sep2’ }
{‘<Sep>’ }
{‘dpixel’ }
ans =
TableProperties with properties:
Description: ‘Surface Profile’
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Idx’ ‘YPos(mm)’ ‘Sep1’ ‘Sep2’ ‘<Sep>’ ‘dpixel’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
Custom Properties (access using t.Properties.CustomProperties.<name>):
ScanStart: "29-Jan-2025 09:41:35"
ScanTime: ‘174.2796’
But then the file looks like this:
So no headings.
And When i also try to load via readtable – all of the description and custom propeerrties are not present
ans =
TableProperties with properties:
Description: ”
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Var1’ ‘Var2’ ‘Var3’ ‘Var4’ ‘Var5’ ‘Var6’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
CustomProperties: No custom properties are set.
Use addprop and rmprop to modify CustomProperties. writetable, uitable MATLAB Answers — New Questions
How to fix an error that the ‘MATLAB Vault is unavailable’ when using the commands listSecrets or setSecret?
I use the MATLAB vault functions to store secrets like logins, passwords, etc in MATLAB 2024a.
It had been working perfectly fine for several months, but suddenly whenever I call any functions like listSecrets, getSecret, setSecret I get this error:
Unable to call ‘listSecrets’. The MATLAB Vault is unavailable.
I have tried the following with no luck:
restarting MATLAB
restarting my PC
re-installing MATLAB
I got this error once before, but after restarting MATLAB it went away. But now, no amount of restarting MATLAB has been able to fix it.
Is there a way to fix this error?I use the MATLAB vault functions to store secrets like logins, passwords, etc in MATLAB 2024a.
It had been working perfectly fine for several months, but suddenly whenever I call any functions like listSecrets, getSecret, setSecret I get this error:
Unable to call ‘listSecrets’. The MATLAB Vault is unavailable.
I have tried the following with no luck:
restarting MATLAB
restarting my PC
re-installing MATLAB
I got this error once before, but after restarting MATLAB it went away. But now, no amount of restarting MATLAB has been able to fix it.
Is there a way to fix this error? I use the MATLAB vault functions to store secrets like logins, passwords, etc in MATLAB 2024a.
It had been working perfectly fine for several months, but suddenly whenever I call any functions like listSecrets, getSecret, setSecret I get this error:
Unable to call ‘listSecrets’. The MATLAB Vault is unavailable.
I have tried the following with no luck:
restarting MATLAB
restarting my PC
re-installing MATLAB
I got this error once before, but after restarting MATLAB it went away. But now, no amount of restarting MATLAB has been able to fix it.
Is there a way to fix this error? vault MATLAB Answers — New Questions
Why my 2 legs inverter doesn’t output the expected voltage?
Why my 2 legs inverter doesn’t output the expected voltage?
I expected the bridge voltage varying binary between 0 and Vbat when I want my motor turns in one sense.
Or -Vbat to 0 whent I want motor turns in the other sense.
instead of the bridge voltage varies from Vbat/2 to Vbat or fron -Vbat to -Vbat/2.
Someone can explain to me how can I fix this issue?Why my 2 legs inverter doesn’t output the expected voltage?
I expected the bridge voltage varying binary between 0 and Vbat when I want my motor turns in one sense.
Or -Vbat to 0 whent I want motor turns in the other sense.
instead of the bridge voltage varies from Vbat/2 to Vbat or fron -Vbat to -Vbat/2.
Someone can explain to me how can I fix this issue? Why my 2 legs inverter doesn’t output the expected voltage?
I expected the bridge voltage varying binary between 0 and Vbat when I want my motor turns in one sense.
Or -Vbat to 0 whent I want motor turns in the other sense.
instead of the bridge voltage varies from Vbat/2 to Vbat or fron -Vbat to -Vbat/2.
Someone can explain to me how can I fix this issue? motor control MATLAB Answers — New Questions
Multiple regression with nonlinear variables
Hello,
I am working with the attached dataset, where the first column represents temperature and the next six columns (2–7) correspond to temperature-dependent properties.
I would like to explore whether it is possible to model temperature as a function of these six properties simultaneously, similar to a multiple regression approach. I have previously done this with linear responses, but in this case, the relationships are nonlinear (sigmoidal, Z-shaped).
I considered using a generalized additive model (GAM), but I have no prior experience with this method and may be overlooking a simpler or more suitable approach.
Could anyone provide insights or suggestions on how to best tackle this?
Thanks in advance! :)Hello,
I am working with the attached dataset, where the first column represents temperature and the next six columns (2–7) correspond to temperature-dependent properties.
I would like to explore whether it is possible to model temperature as a function of these six properties simultaneously, similar to a multiple regression approach. I have previously done this with linear responses, but in this case, the relationships are nonlinear (sigmoidal, Z-shaped).
I considered using a generalized additive model (GAM), but I have no prior experience with this method and may be overlooking a simpler or more suitable approach.
Could anyone provide insights or suggestions on how to best tackle this?
Thanks in advance! 🙂 Hello,
I am working with the attached dataset, where the first column represents temperature and the next six columns (2–7) correspond to temperature-dependent properties.
I would like to explore whether it is possible to model temperature as a function of these six properties simultaneously, similar to a multiple regression approach. I have previously done this with linear responses, but in this case, the relationships are nonlinear (sigmoidal, Z-shaped).
I considered using a generalized additive model (GAM), but I have no prior experience with this method and may be overlooking a simpler or more suitable approach.
Could anyone provide insights or suggestions on how to best tackle this?
Thanks in advance! 🙂 multiple regression, nonlinear, additive models, multiple variables MATLAB Answers — New Questions
fmincon with simulink model
Hello, I’m struggling with fmincon, as I’m still a beginner. I have a Simulink model that simulates the behavior of an electric vehicle and a track specification (maximum speed in different sections, total length).
The model takes as input the throttle and brake pedal pressures (steering is not relevant in this case) and outputs various vehicle dynamics parameters such as speed, jerk, acceleration, and SoC.
My goal is to determine the optimal pedal usage to complete the track while maximizing the remaining SoC, using the results obtained from the model.
I wrote a MATLAB script for this, but the throttle and brake pedal vectors never change—they always remain the same as the initial values u0 that I provide.
Does anyone know what might be causing this issue?
My cost function is:
function [cost, c, ceq] = myCostAndConstraints(u, timeVec, steeringTS, w1, w2, w3, w4, w5, total_distance)
N = length(u)/2;
throttleProfile = u(1:N);
brakeProfile = u(N+1:end);
myThrottleTs = timeseries(throttleProfile, timeVec);
myBrakeTs = timeseries(brakeProfile, timeVec);
in = Simulink.SimulationInput(‘optimization_offline_model’);
in = in.setVariable(‘myThrottleTs’, myThrottleTs);
in = in.setVariable(‘myBrakeTs’, myBrakeTs);
in = in.setVariable(‘steeringWheelAngle_ts’, steeringTS);
try
simOut = sim(in);
catch ME
warning("Simulation error: %s" + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
try
timeSim = simOut.tout;
speedData = simOut.v_z.Data;
SoCData = simOut.SoC.Data;
jerkData = simOut.j_z.Data;
distanceData = simOut.distance.Data;
catch ME
warning("Error extracting signals: " + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
SoC_final = SoCData(end);
time_elapsed = timeSim(end);
distance_final = distanceData(end);
penalty = 0;
if any(SoCData < 0.2)
penalty = penalty + w1 * (0.2 – min(SoCData(SoCData<0.2)));
end
vLimHard = 41.5;
violV = speedData – vLimHard;
violV(violV<0) = 0;
if any(violV > 0)
penalty = penalty + w5 * sum(violV);
end
avgJerk = mean(jerkData);
maxJerk = max(abs(jerkData));
penalty = penalty + w3*(max(0, 0.2 – avgJerk))^2 + w3*(max(0, avgJerk – 0.7))^2;
if avgJerk > 0.6
penalty = penalty + w3*(avgJerk – 0.6);
end
if maxJerk > 0.9
penalty = penalty + w3*(maxJerk – 0.9);
end
cost = – w1*SoC_final + w2*(time_elapsed) + w4 * abs(total_distance – distance_final) + penalty;
disp("Cost function =" + cost);
vLimVec = getVelocityLimit(distanceData, vLimHard);
c = speedData – vLimVec;
ceq = throttleProfile .* brakeProfile;
endHello, I’m struggling with fmincon, as I’m still a beginner. I have a Simulink model that simulates the behavior of an electric vehicle and a track specification (maximum speed in different sections, total length).
The model takes as input the throttle and brake pedal pressures (steering is not relevant in this case) and outputs various vehicle dynamics parameters such as speed, jerk, acceleration, and SoC.
My goal is to determine the optimal pedal usage to complete the track while maximizing the remaining SoC, using the results obtained from the model.
I wrote a MATLAB script for this, but the throttle and brake pedal vectors never change—they always remain the same as the initial values u0 that I provide.
Does anyone know what might be causing this issue?
My cost function is:
function [cost, c, ceq] = myCostAndConstraints(u, timeVec, steeringTS, w1, w2, w3, w4, w5, total_distance)
N = length(u)/2;
throttleProfile = u(1:N);
brakeProfile = u(N+1:end);
myThrottleTs = timeseries(throttleProfile, timeVec);
myBrakeTs = timeseries(brakeProfile, timeVec);
in = Simulink.SimulationInput(‘optimization_offline_model’);
in = in.setVariable(‘myThrottleTs’, myThrottleTs);
in = in.setVariable(‘myBrakeTs’, myBrakeTs);
in = in.setVariable(‘steeringWheelAngle_ts’, steeringTS);
try
simOut = sim(in);
catch ME
warning("Simulation error: %s" + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
try
timeSim = simOut.tout;
speedData = simOut.v_z.Data;
SoCData = simOut.SoC.Data;
jerkData = simOut.j_z.Data;
distanceData = simOut.distance.Data;
catch ME
warning("Error extracting signals: " + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
SoC_final = SoCData(end);
time_elapsed = timeSim(end);
distance_final = distanceData(end);
penalty = 0;
if any(SoCData < 0.2)
penalty = penalty + w1 * (0.2 – min(SoCData(SoCData<0.2)));
end
vLimHard = 41.5;
violV = speedData – vLimHard;
violV(violV<0) = 0;
if any(violV > 0)
penalty = penalty + w5 * sum(violV);
end
avgJerk = mean(jerkData);
maxJerk = max(abs(jerkData));
penalty = penalty + w3*(max(0, 0.2 – avgJerk))^2 + w3*(max(0, avgJerk – 0.7))^2;
if avgJerk > 0.6
penalty = penalty + w3*(avgJerk – 0.6);
end
if maxJerk > 0.9
penalty = penalty + w3*(maxJerk – 0.9);
end
cost = – w1*SoC_final + w2*(time_elapsed) + w4 * abs(total_distance – distance_final) + penalty;
disp("Cost function =" + cost);
vLimVec = getVelocityLimit(distanceData, vLimHard);
c = speedData – vLimVec;
ceq = throttleProfile .* brakeProfile;
end Hello, I’m struggling with fmincon, as I’m still a beginner. I have a Simulink model that simulates the behavior of an electric vehicle and a track specification (maximum speed in different sections, total length).
The model takes as input the throttle and brake pedal pressures (steering is not relevant in this case) and outputs various vehicle dynamics parameters such as speed, jerk, acceleration, and SoC.
My goal is to determine the optimal pedal usage to complete the track while maximizing the remaining SoC, using the results obtained from the model.
I wrote a MATLAB script for this, but the throttle and brake pedal vectors never change—they always remain the same as the initial values u0 that I provide.
Does anyone know what might be causing this issue?
My cost function is:
function [cost, c, ceq] = myCostAndConstraints(u, timeVec, steeringTS, w1, w2, w3, w4, w5, total_distance)
N = length(u)/2;
throttleProfile = u(1:N);
brakeProfile = u(N+1:end);
myThrottleTs = timeseries(throttleProfile, timeVec);
myBrakeTs = timeseries(brakeProfile, timeVec);
in = Simulink.SimulationInput(‘optimization_offline_model’);
in = in.setVariable(‘myThrottleTs’, myThrottleTs);
in = in.setVariable(‘myBrakeTs’, myBrakeTs);
in = in.setVariable(‘steeringWheelAngle_ts’, steeringTS);
try
simOut = sim(in);
catch ME
warning("Simulation error: %s" + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
try
timeSim = simOut.tout;
speedData = simOut.v_z.Data;
SoCData = simOut.SoC.Data;
jerkData = simOut.j_z.Data;
distanceData = simOut.distance.Data;
catch ME
warning("Error extracting signals: " + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
SoC_final = SoCData(end);
time_elapsed = timeSim(end);
distance_final = distanceData(end);
penalty = 0;
if any(SoCData < 0.2)
penalty = penalty + w1 * (0.2 – min(SoCData(SoCData<0.2)));
end
vLimHard = 41.5;
violV = speedData – vLimHard;
violV(violV<0) = 0;
if any(violV > 0)
penalty = penalty + w5 * sum(violV);
end
avgJerk = mean(jerkData);
maxJerk = max(abs(jerkData));
penalty = penalty + w3*(max(0, 0.2 – avgJerk))^2 + w3*(max(0, avgJerk – 0.7))^2;
if avgJerk > 0.6
penalty = penalty + w3*(avgJerk – 0.6);
end
if maxJerk > 0.9
penalty = penalty + w3*(maxJerk – 0.9);
end
cost = – w1*SoC_final + w2*(time_elapsed) + w4 * abs(total_distance – distance_final) + penalty;
disp("Cost function =" + cost);
vLimVec = getVelocityLimit(distanceData, vLimHard);
c = speedData – vLimVec;
ceq = throttleProfile .* brakeProfile;
end fmincon, simulink MATLAB Answers — New Questions
How to use index an image using color inequality?
I have an image that I would like to turn black or white depending on a user defined color RGB value associated with the scale in the image. How would I do this?I have an image that I would like to turn black or white depending on a user defined color RGB value associated with the scale in the image. How would I do this? I have an image that I would like to turn black or white depending on a user defined color RGB value associated with the scale in the image. How would I do this? indexing, image processing MATLAB Answers — New Questions
Definition of “Frame” for Recurrent models
Hi all,
I am profiling the performance of the MATLAB Deep Learning HDL Toolbox for LSTM-based models.
When estimating the processor’s performance with the estimatePerformance function, I couldn’t find a clear definition of the term "Frame" in the context of recurrent models.
Does it refer to a single element within the sequence to be processed (i.e. a timestep), or does it represent the entire sequence?
Since changing the number of timesteps in the model doesn’t affect the processing time estimate for 1 frame, I am assuming it refers to a single element of the sequence. However, I would appreciate confirmation or clarification on this.
Thanks in advance for your help!Hi all,
I am profiling the performance of the MATLAB Deep Learning HDL Toolbox for LSTM-based models.
When estimating the processor’s performance with the estimatePerformance function, I couldn’t find a clear definition of the term "Frame" in the context of recurrent models.
Does it refer to a single element within the sequence to be processed (i.e. a timestep), or does it represent the entire sequence?
Since changing the number of timesteps in the model doesn’t affect the processing time estimate for 1 frame, I am assuming it refers to a single element of the sequence. However, I would appreciate confirmation or clarification on this.
Thanks in advance for your help! Hi all,
I am profiling the performance of the MATLAB Deep Learning HDL Toolbox for LSTM-based models.
When estimating the processor’s performance with the estimatePerformance function, I couldn’t find a clear definition of the term "Frame" in the context of recurrent models.
Does it refer to a single element within the sequence to be processed (i.e. a timestep), or does it represent the entire sequence?
Since changing the number of timesteps in the model doesn’t affect the processing time estimate for 1 frame, I am assuming it refers to a single element of the sequence. However, I would appreciate confirmation or clarification on this.
Thanks in advance for your help! lstm, deep learning hdl toolbox MATLAB Answers — New Questions
How does multithresh and imquantize works
Can anyone explain about multithresh and imquantize? I’ve read the documentation regarding it but I don’t really understand how does it works and how do they relate to each other.
If i have a thresh = multithresh(A,4)
Does it means that it returns 4 threshold values from the image? How does the system decides which values to return? And we have imquantize(A,thresh). What would happen?Can anyone explain about multithresh and imquantize? I’ve read the documentation regarding it but I don’t really understand how does it works and how do they relate to each other.
If i have a thresh = multithresh(A,4)
Does it means that it returns 4 threshold values from the image? How does the system decides which values to return? And we have imquantize(A,thresh). What would happen? Can anyone explain about multithresh and imquantize? I’ve read the documentation regarding it but I don’t really understand how does it works and how do they relate to each other.
If i have a thresh = multithresh(A,4)
Does it means that it returns 4 threshold values from the image? How does the system decides which values to return? And we have imquantize(A,thresh). What would happen? image processing MATLAB Answers — New Questions
simpowersysteme discret simulation stability issue
I want to analyse the transient stability of a simple system over a long period of time. I do this because my ultimate goal is to run the simulation with real-time simulator for education purpose.
My model is really simple, one PV bus synchronous generator connected to a infinite swing bus via a bunch of inductance and resistance in serie and parallel. I simulate a fault at 0.5 sec and since i am simulating dampingless generator i expect my system to oscillate for the infinity
But.. When i run my model in phasor mode it run well and it do not diverge. But when i run it in discret mode with 20 us (as it will be on my real time simulator) the mecanical angle after the fault always increase until it reach instability.
btw i add up some extra load to help numerical stability as suggested in the help panel of the synchronous generator.I want to analyse the transient stability of a simple system over a long period of time. I do this because my ultimate goal is to run the simulation with real-time simulator for education purpose.
My model is really simple, one PV bus synchronous generator connected to a infinite swing bus via a bunch of inductance and resistance in serie and parallel. I simulate a fault at 0.5 sec and since i am simulating dampingless generator i expect my system to oscillate for the infinity
But.. When i run my model in phasor mode it run well and it do not diverge. But when i run it in discret mode with 20 us (as it will be on my real time simulator) the mecanical angle after the fault always increase until it reach instability.
btw i add up some extra load to help numerical stability as suggested in the help panel of the synchronous generator. I want to analyse the transient stability of a simple system over a long period of time. I do this because my ultimate goal is to run the simulation with real-time simulator for education purpose.
My model is really simple, one PV bus synchronous generator connected to a infinite swing bus via a bunch of inductance and resistance in serie and parallel. I simulate a fault at 0.5 sec and since i am simulating dampingless generator i expect my system to oscillate for the infinity
But.. When i run my model in phasor mode it run well and it do not diverge. But when i run it in discret mode with 20 us (as it will be on my real time simulator) the mecanical angle after the fault always increase until it reach instability.
btw i add up some extra load to help numerical stability as suggested in the help panel of the synchronous generator. simulink, simpowersystems, simulation MATLAB Answers — New Questions
How can I break a WHILE or a FOR loop in Simulink?
I want to break a for loop or a while loop in Simulink. For instance, we have break statement in C. How do I do the same in Simulink?I want to break a for loop or a while loop in Simulink. For instance, we have break statement in C. How do I do the same in Simulink? I want to break a for loop or a while loop in Simulink. For instance, we have break statement in C. How do I do the same in Simulink? break, for loop, while loop MATLAB Answers — New Questions
How do I obtain area under selected region on figure?
I am trying to select peak start and end points and calculate area under the curve for several regions of interest. Is there an easy way to do it quickly on the figure itself? A sample image is attached with selected (X1,Y1) and (X2,Y2) points as an example.I am trying to select peak start and end points and calculate area under the curve for several regions of interest. Is there an easy way to do it quickly on the figure itself? A sample image is attached with selected (X1,Y1) and (X2,Y2) points as an example. I am trying to select peak start and end points and calculate area under the curve for several regions of interest. Is there an easy way to do it quickly on the figure itself? A sample image is attached with selected (X1,Y1) and (X2,Y2) points as an example. figure, image processing, matlab MATLAB Answers — New Questions
three phase transformer simulation
Hi
I am doing simulation for a three-phase transformer (50/11) KV with is feeding by avoltage source, while the secondery is coneectred to ta fixed load.
when I run the simulation. the voltage measurement in the primary winding for the transformer is very small and there is no current, the same thing is happing in the secondary.
I am going to upload the simulation file. anyone can help ?Hi
I am doing simulation for a three-phase transformer (50/11) KV with is feeding by avoltage source, while the secondery is coneectred to ta fixed load.
when I run the simulation. the voltage measurement in the primary winding for the transformer is very small and there is no current, the same thing is happing in the secondary.
I am going to upload the simulation file. anyone can help ? Hi
I am doing simulation for a three-phase transformer (50/11) KV with is feeding by avoltage source, while the secondery is coneectred to ta fixed load.
when I run the simulation. the voltage measurement in the primary winding for the transformer is very small and there is no current, the same thing is happing in the secondary.
I am going to upload the simulation file. anyone can help ? simulation, transformer MATLAB Answers — New Questions