Category: Matlab
Category Archives: Matlab
Simulating Induction motor inter-turn short circuit faults
Hi! Using Simulink / Simscape I wish to Simulate an Induction Motor for getting normal operation and inter-turn short circuit fault data for training my Machine learning based fault classifier. I basically desire a model that incorporates saturation and iron losses effects as well. Any help and guidance is requested.Hi! Using Simulink / Simscape I wish to Simulate an Induction Motor for getting normal operation and inter-turn short circuit fault data for training my Machine learning based fault classifier. I basically desire a model that incorporates saturation and iron losses effects as well. Any help and guidance is requested. Hi! Using Simulink / Simscape I wish to Simulate an Induction Motor for getting normal operation and inter-turn short circuit fault data for training my Machine learning based fault classifier. I basically desire a model that incorporates saturation and iron losses effects as well. Any help and guidance is requested. induction-motor model, simulink, simscape MATLAB Answers — New Questions
Assigning plot to an existing axes Matlab GUI
Hi,
I have a GUI in Matlab and several functions in it. One function is for plotting a figure, I need to assign it to an existing axes in GUI. I have tried several options, nothing has worked out yet.
Code below is the current option I had tried before I asked here.
set(‘CurrentAxes’,’axes11′)
plot(VyQRS(:,2));
grid on
The plot of VyQRS I need to assign to axes11.
Could you please give me any hint?Hi,
I have a GUI in Matlab and several functions in it. One function is for plotting a figure, I need to assign it to an existing axes in GUI. I have tried several options, nothing has worked out yet.
Code below is the current option I had tried before I asked here.
set(‘CurrentAxes’,’axes11′)
plot(VyQRS(:,2));
grid on
The plot of VyQRS I need to assign to axes11.
Could you please give me any hint? Hi,
I have a GUI in Matlab and several functions in it. One function is for plotting a figure, I need to assign it to an existing axes in GUI. I have tried several options, nothing has worked out yet.
Code below is the current option I had tried before I asked here.
set(‘CurrentAxes’,’axes11′)
plot(VyQRS(:,2));
grid on
The plot of VyQRS I need to assign to axes11.
Could you please give me any hint? matlab gui, plotting, guide MATLAB Answers — New Questions
Construction of subplots for the comparison of two models
Hi Everyone!
I would like to know what kind of subplot (code) I could use to make similar graphics.
Best regard,Hi Everyone!
I would like to know what kind of subplot (code) I could use to make similar graphics.
Best regard, Hi Everyone!
I would like to know what kind of subplot (code) I could use to make similar graphics.
Best regard, two mdels comparison, comparison models MATLAB Answers — New Questions
Execution times and the “pause” function
I have a question about a strange phenomenon I have been noticing for some time whilst working with Matlab and which has now become somewhat acute.
When I run scripts which are relatively demanding on my computer, pausing and immediately unpausing the execution weirdly appears to speed up the execution of the rest of the script.
The current example is this:
I am running a simulation model, which is essentially just one big loop representing simulation periods . Within this loop there is another loop which is entered only under a certain condition. If this second loop is entered in some simulation period t, the simualtion of this particular period naturally takes longer than that of the other ones as more operations are executed.
Essentially the programm looks like this:
for t=1:T
do stuff
if condition holds
for tt=1:TT
do more stuff
end
end
end
The problem I have is the following: After the second, inner loop is entered, all following simulation periods take longer to execute, even when the condition does not hold. I have gone into debug mode and can 100% confirm that the second loop is not entered in other simulation periods. Nevertheless those periods take longer to execute after the second loop has been entered once in a previous period.
Additionally, if i pause the execution of the script manually after the second loop has been entered and exited again and then continue, the script speeds back up and the rest of the periods are simulated at the usual speed. More generally, I often find that if a script runs slowly I can speed it up significantly by pausing and unpausing.
Does anyone know what might be causing this?
PS: After some additonal experimentation it seems that this phenomenon only occurs if I click the pause button in the GUI, i.e. if I enter debug mode and then pess continue. Simply inserting pause(n) under some condition into the script does not cause this change in execution speeds.I have a question about a strange phenomenon I have been noticing for some time whilst working with Matlab and which has now become somewhat acute.
When I run scripts which are relatively demanding on my computer, pausing and immediately unpausing the execution weirdly appears to speed up the execution of the rest of the script.
The current example is this:
I am running a simulation model, which is essentially just one big loop representing simulation periods . Within this loop there is another loop which is entered only under a certain condition. If this second loop is entered in some simulation period t, the simualtion of this particular period naturally takes longer than that of the other ones as more operations are executed.
Essentially the programm looks like this:
for t=1:T
do stuff
if condition holds
for tt=1:TT
do more stuff
end
end
end
The problem I have is the following: After the second, inner loop is entered, all following simulation periods take longer to execute, even when the condition does not hold. I have gone into debug mode and can 100% confirm that the second loop is not entered in other simulation periods. Nevertheless those periods take longer to execute after the second loop has been entered once in a previous period.
Additionally, if i pause the execution of the script manually after the second loop has been entered and exited again and then continue, the script speeds back up and the rest of the periods are simulated at the usual speed. More generally, I often find that if a script runs slowly I can speed it up significantly by pausing and unpausing.
Does anyone know what might be causing this?
PS: After some additonal experimentation it seems that this phenomenon only occurs if I click the pause button in the GUI, i.e. if I enter debug mode and then pess continue. Simply inserting pause(n) under some condition into the script does not cause this change in execution speeds. I have a question about a strange phenomenon I have been noticing for some time whilst working with Matlab and which has now become somewhat acute.
When I run scripts which are relatively demanding on my computer, pausing and immediately unpausing the execution weirdly appears to speed up the execution of the rest of the script.
The current example is this:
I am running a simulation model, which is essentially just one big loop representing simulation periods . Within this loop there is another loop which is entered only under a certain condition. If this second loop is entered in some simulation period t, the simualtion of this particular period naturally takes longer than that of the other ones as more operations are executed.
Essentially the programm looks like this:
for t=1:T
do stuff
if condition holds
for tt=1:TT
do more stuff
end
end
end
The problem I have is the following: After the second, inner loop is entered, all following simulation periods take longer to execute, even when the condition does not hold. I have gone into debug mode and can 100% confirm that the second loop is not entered in other simulation periods. Nevertheless those periods take longer to execute after the second loop has been entered once in a previous period.
Additionally, if i pause the execution of the script manually after the second loop has been entered and exited again and then continue, the script speeds back up and the rest of the periods are simulated at the usual speed. More generally, I often find that if a script runs slowly I can speed it up significantly by pausing and unpausing.
Does anyone know what might be causing this?
PS: After some additonal experimentation it seems that this phenomenon only occurs if I click the pause button in the GUI, i.e. if I enter debug mode and then pess continue. Simply inserting pause(n) under some condition into the script does not cause this change in execution speeds. execution time, pause, loops MATLAB Answers — New Questions
finding local maximum/minimum for a function
how to find the local extreme values of the function xy-x^2-y^2-2x-2y+4how to find the local extreme values of the function xy-x^2-y^2-2x-2y+4 how to find the local extreme values of the function xy-x^2-y^2-2x-2y+4 matlab, maxima MATLAB Answers — New Questions
How to reduce current ripple in a closed loop buck converter for a PV li-ion battery charger??
If i test the buck converter model alone i get a smooth current and voltage signal,
but when i add the battery and the control logic, the current signal has a very high peak to peak amplitude.
Do you know why us this behavior??
Thanks.If i test the buck converter model alone i get a smooth current and voltage signal,
but when i add the battery and the control logic, the current signal has a very high peak to peak amplitude.
Do you know why us this behavior??
Thanks. If i test the buck converter model alone i get a smooth current and voltage signal,
but when i add the battery and the control logic, the current signal has a very high peak to peak amplitude.
Do you know why us this behavior??
Thanks. li-ion, battery charger, buck converter, solar energy, current ripple, power_electronics_control, battery_system_management MATLAB Answers — New Questions
Passing data by reference to Matlab toolbox functions for code generation
Hello everyone.
I am working on optimization of generated code. My algorithm uses toolbox function interp1 for linear interpolation. Code for it is generated by Matlab embedded coder. I want to prevent copying of input arrays to it. Normally function doesn’t define input argument as in/out, but algorithm doesn’t use them afterwards and copy is redundant. Is there a way to tell Matlab coder about it to do optimization.Hello everyone.
I am working on optimization of generated code. My algorithm uses toolbox function interp1 for linear interpolation. Code for it is generated by Matlab embedded coder. I want to prevent copying of input arrays to it. Normally function doesn’t define input argument as in/out, but algorithm doesn’t use them afterwards and copy is redundant. Is there a way to tell Matlab coder about it to do optimization. Hello everyone.
I am working on optimization of generated code. My algorithm uses toolbox function interp1 for linear interpolation. Code for it is generated by Matlab embedded coder. I want to prevent copying of input arrays to it. Normally function doesn’t define input argument as in/out, but algorithm doesn’t use them afterwards and copy is redundant. Is there a way to tell Matlab coder about it to do optimization. matlab coder, memory, embedded coder MATLAB Answers — New Questions
Can pdepe solve a system of two second-order equations?
I am trying to figure out pdepe and how to use it to solve a higher order equation written as multiple second order equations. Even though I am trying to solve a more complex equation in the future I want to start with a simple case
.
My idea is to rewrite it by including a second variable
where
.
I chose the spatial coordinate to range from x=linsapce(0,2*pi,N) to ensure that my initial conditions satisfy my boundary conditions (see below).
In pdepe terms I wrote
function [c,f,s] = pdex1pde(x,t,u,dudx)
global D
c = [1 ; 0];
f = [D*dudx(2); dudx(1)];
s = [0; -u(2)]; %where q=u(2);
end
and providing some initial condition (from 0 to 2pi)
function u0 = pdex1ic(x)
init = 1-cos(x);
d2init_dx2 = cos(x);
u0 = [init; d2init_dx2]
end
For the boundary conditions I just used a Neumann boundary for each boundary
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = [0;0];
ql = [1;1];
pr = [0;0];
qr = [1;1];
end
Now pdepe gives me a warning that it could not converge at time t=0 and I don’t get a result.
Is there something that I am missing?
I had a look at other questions about this topic and already stumbled upon this github page (https://github.com/wgreene310/pdepe-examples), but I don’t really understand it without the written equations.
Thank you very much for answering.I am trying to figure out pdepe and how to use it to solve a higher order equation written as multiple second order equations. Even though I am trying to solve a more complex equation in the future I want to start with a simple case
.
My idea is to rewrite it by including a second variable
where
.
I chose the spatial coordinate to range from x=linsapce(0,2*pi,N) to ensure that my initial conditions satisfy my boundary conditions (see below).
In pdepe terms I wrote
function [c,f,s] = pdex1pde(x,t,u,dudx)
global D
c = [1 ; 0];
f = [D*dudx(2); dudx(1)];
s = [0; -u(2)]; %where q=u(2);
end
and providing some initial condition (from 0 to 2pi)
function u0 = pdex1ic(x)
init = 1-cos(x);
d2init_dx2 = cos(x);
u0 = [init; d2init_dx2]
end
For the boundary conditions I just used a Neumann boundary for each boundary
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = [0;0];
ql = [1;1];
pr = [0;0];
qr = [1;1];
end
Now pdepe gives me a warning that it could not converge at time t=0 and I don’t get a result.
Is there something that I am missing?
I had a look at other questions about this topic and already stumbled upon this github page (https://github.com/wgreene310/pdepe-examples), but I don’t really understand it without the written equations.
Thank you very much for answering. I am trying to figure out pdepe and how to use it to solve a higher order equation written as multiple second order equations. Even though I am trying to solve a more complex equation in the future I want to start with a simple case
.
My idea is to rewrite it by including a second variable
where
.
I chose the spatial coordinate to range from x=linsapce(0,2*pi,N) to ensure that my initial conditions satisfy my boundary conditions (see below).
In pdepe terms I wrote
function [c,f,s] = pdex1pde(x,t,u,dudx)
global D
c = [1 ; 0];
f = [D*dudx(2); dudx(1)];
s = [0; -u(2)]; %where q=u(2);
end
and providing some initial condition (from 0 to 2pi)
function u0 = pdex1ic(x)
init = 1-cos(x);
d2init_dx2 = cos(x);
u0 = [init; d2init_dx2]
end
For the boundary conditions I just used a Neumann boundary for each boundary
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = [0;0];
ql = [1;1];
pr = [0;0];
qr = [1;1];
end
Now pdepe gives me a warning that it could not converge at time t=0 and I don’t get a result.
Is there something that I am missing?
I had a look at other questions about this topic and already stumbled upon this github page (https://github.com/wgreene310/pdepe-examples), but I don’t really understand it without the written equations.
Thank you very much for answering. pdepe, pde, system of equations MATLAB Answers — New Questions
getrect and ginput are not supported by codegen
Hi guys. I am developing a .DLL using the command "codegen", and in an intermediate process I need to select some data from a plot made by the .DLL, then the operations dependent on this selected data continue. For this I am using the "getrect" and "ginput" functions, however, when compiling the .DLL a message appears saying that these functions are not supported by "codegen". In that sense, is there any other function that is supported by "codegen" that I can use?Hi guys. I am developing a .DLL using the command "codegen", and in an intermediate process I need to select some data from a plot made by the .DLL, then the operations dependent on this selected data continue. For this I am using the "getrect" and "ginput" functions, however, when compiling the .DLL a message appears saying that these functions are not supported by "codegen". In that sense, is there any other function that is supported by "codegen" that I can use? Hi guys. I am developing a .DLL using the command "codegen", and in an intermediate process I need to select some data from a plot made by the .DLL, then the operations dependent on this selected data continue. For this I am using the "getrect" and "ginput" functions, however, when compiling the .DLL a message appears saying that these functions are not supported by "codegen". In that sense, is there any other function that is supported by "codegen" that I can use? codegen, dll MATLAB Answers — New Questions
PAPR (Peak to Average Power Ratio) of OFDM(Orthogonal Frequency Division Multiplexing)
will the PAPR(Peak to Average Power Ratio) of OFDM (Orthogonal Frequency Division Multiplexing) be effected if we use different modulation schemes?
1) effect on PAPR using M-QAM
2) effect on PAPR using M-PSKwill the PAPR(Peak to Average Power Ratio) of OFDM (Orthogonal Frequency Division Multiplexing) be effected if we use different modulation schemes?
1) effect on PAPR using M-QAM
2) effect on PAPR using M-PSK will the PAPR(Peak to Average Power Ratio) of OFDM (Orthogonal Frequency Division Multiplexing) be effected if we use different modulation schemes?
1) effect on PAPR using M-QAM
2) effect on PAPR using M-PSK papr of ofdm, papr (peak to average power ratio) of ofdm(orthogonal frequency division multiplexing) MATLAB Answers — New Questions
Simulink : How to inject real and image current into three phase power grid by using discrete mode powergui
Hello,everyone.
I have trouble when I setting real and image current respectly and inject them to infinite bus.
I need to use powergui in discrete phasor mode to simulate the system,but I want to use powergui in discrete mode.
Is this possible to inject real and image current into three phase power system by powergui in discrete mode?
Thank you for your reply!!Hello,everyone.
I have trouble when I setting real and image current respectly and inject them to infinite bus.
I need to use powergui in discrete phasor mode to simulate the system,but I want to use powergui in discrete mode.
Is this possible to inject real and image current into three phase power system by powergui in discrete mode?
Thank you for your reply!! Hello,everyone.
I have trouble when I setting real and image current respectly and inject them to infinite bus.
I need to use powergui in discrete phasor mode to simulate the system,but I want to use powergui in discrete mode.
Is this possible to inject real and image current into three phase power system by powergui in discrete mode?
Thank you for your reply!! simscape, simulink MATLAB Answers — New Questions
Problem with mvregress when working with cell arrays
Hi,
I have a problem when using multivariate regression function (mvregress) available in matlab.
I have a cell array with 20 cells in each of which there are three values as inputs and my target output is a vector with 20 values. When I load this data and call mvregress function, it gives the error: "Undefined function ‘isnan’ for input arguments of type ‘cell’."
To eliminate this problem I tried using: data = cellfun(@isnan,originaldata,’UniformOutput’,false)
But this makes all my values zero.
My code is given below:
load mywork1.mat
[beta,Sigma, resid] = mvregress(targetvalues’,originaldata)
Since it gives the error ("Undefined function ‘isnan’ for input arguments of type ‘cell’."), I tried the following
data = cellfun(@isnan,originaldata,’UniformOutput’,false)
But then all my data cells are replaced with zeros.
How can I resolve this issue and perform multivariate regression on these data?
I have attached the data set.
Thank you in advance.Hi,
I have a problem when using multivariate regression function (mvregress) available in matlab.
I have a cell array with 20 cells in each of which there are three values as inputs and my target output is a vector with 20 values. When I load this data and call mvregress function, it gives the error: "Undefined function ‘isnan’ for input arguments of type ‘cell’."
To eliminate this problem I tried using: data = cellfun(@isnan,originaldata,’UniformOutput’,false)
But this makes all my values zero.
My code is given below:
load mywork1.mat
[beta,Sigma, resid] = mvregress(targetvalues’,originaldata)
Since it gives the error ("Undefined function ‘isnan’ for input arguments of type ‘cell’."), I tried the following
data = cellfun(@isnan,originaldata,’UniformOutput’,false)
But then all my data cells are replaced with zeros.
How can I resolve this issue and perform multivariate regression on these data?
I have attached the data set.
Thank you in advance. Hi,
I have a problem when using multivariate regression function (mvregress) available in matlab.
I have a cell array with 20 cells in each of which there are three values as inputs and my target output is a vector with 20 values. When I load this data and call mvregress function, it gives the error: "Undefined function ‘isnan’ for input arguments of type ‘cell’."
To eliminate this problem I tried using: data = cellfun(@isnan,originaldata,’UniformOutput’,false)
But this makes all my values zero.
My code is given below:
load mywork1.mat
[beta,Sigma, resid] = mvregress(targetvalues’,originaldata)
Since it gives the error ("Undefined function ‘isnan’ for input arguments of type ‘cell’."), I tried the following
data = cellfun(@isnan,originaldata,’UniformOutput’,false)
But then all my data cells are replaced with zeros.
How can I resolve this issue and perform multivariate regression on these data?
I have attached the data set.
Thank you in advance. regression, mvregress, isnan MATLAB Answers — New Questions
error in downloading trial version
following statement appears again and again after retry
The following error was detected while downloading foundation/httpproxy_win64_1550744841.enc:
Wrong number of bytes: Expected 74382, got 5291following statement appears again and again after retry
The following error was detected while downloading foundation/httpproxy_win64_1550744841.enc:
Wrong number of bytes: Expected 74382, got 5291 following statement appears again and again after retry
The following error was detected while downloading foundation/httpproxy_win64_1550744841.enc:
Wrong number of bytes: Expected 74382, got 5291 trial version, student version, wrong number of bytes MATLAB Answers — New Questions
Can’t get ‘ValueChangedFcn’ callback to work for ‘uidatepicker ‘
Hi,
I’m would like to have a date picker window on my main app window, and I’d like something to happen whenever the date is changed. The help file says I can call a function using the ‘ValueChangedFcn’ callback, but I can’t get it to work. This is the relevant piece of code:
methods (Access = private)
function test(app)
uialert(app.UIFigure, ‘It works!’, ‘It works!’, ‘Icon’,’help’);
end
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
uidatepicker(app.UIFigure, ‘Position’, [780 350 100 22], ‘ValueChangedFcn’, test(app))
I get this error message – Error using app1/test
Too many output arguments.
Error in app1 (line 431)
runStartupFcn(app, @startupFcn)
Any ideas?Hi,
I’m would like to have a date picker window on my main app window, and I’d like something to happen whenever the date is changed. The help file says I can call a function using the ‘ValueChangedFcn’ callback, but I can’t get it to work. This is the relevant piece of code:
methods (Access = private)
function test(app)
uialert(app.UIFigure, ‘It works!’, ‘It works!’, ‘Icon’,’help’);
end
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
uidatepicker(app.UIFigure, ‘Position’, [780 350 100 22], ‘ValueChangedFcn’, test(app))
I get this error message – Error using app1/test
Too many output arguments.
Error in app1 (line 431)
runStartupFcn(app, @startupFcn)
Any ideas? Hi,
I’m would like to have a date picker window on my main app window, and I’d like something to happen whenever the date is changed. The help file says I can call a function using the ‘ValueChangedFcn’ callback, but I can’t get it to work. This is the relevant piece of code:
methods (Access = private)
function test(app)
uialert(app.UIFigure, ‘It works!’, ‘It works!’, ‘Icon’,’help’);
end
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
uidatepicker(app.UIFigure, ‘Position’, [780 350 100 22], ‘ValueChangedFcn’, test(app))
I get this error message – Error using app1/test
Too many output arguments.
Error in app1 (line 431)
runStartupFcn(app, @startupFcn)
Any ideas? valuechangedfcn, uidatepicker MATLAB Answers — New Questions
How to click into the heatmap created inside a UI panel?
I’m working on building an interactive Heatmap in Matlab UI. added a UI Panel to the interface and populated the heatmap within the panel. Now that I know how to get the row and column upon clicking the Heatmap cell, the issue now is I’m not able to actually click into the heatmap within the UI Panel. I tried using the “WindowButtonDownFcn”, but was only able to click into any blank area within the UI Panel. Once I click on the heatmap in the UI panel, there is no response at all.
May I know how I could click into the heatmap created inside the UI Panel? Thanks!I’m working on building an interactive Heatmap in Matlab UI. added a UI Panel to the interface and populated the heatmap within the panel. Now that I know how to get the row and column upon clicking the Heatmap cell, the issue now is I’m not able to actually click into the heatmap within the UI Panel. I tried using the “WindowButtonDownFcn”, but was only able to click into any blank area within the UI Panel. Once I click on the heatmap in the UI panel, there is no response at all.
May I know how I could click into the heatmap created inside the UI Panel? Thanks! I’m working on building an interactive Heatmap in Matlab UI. added a UI Panel to the interface and populated the heatmap within the panel. Now that I know how to get the row and column upon clicking the Heatmap cell, the issue now is I’m not able to actually click into the heatmap within the UI Panel. I tried using the “WindowButtonDownFcn”, but was only able to click into any blank area within the UI Panel. Once I click on the heatmap in the UI panel, there is no response at all.
May I know how I could click into the heatmap created inside the UI Panel? Thanks! heatmap, appdesigner, matlab gui MATLAB Answers — New Questions
how to recombine blocks of an image into one?
Dear sir,
I am working on Watermarking. I divided a color host image into blocks using mat2cell. i hid watermark images in respective blocks. i wanted to know how i can recombine the watermarked blocks?Dear sir,
I am working on Watermarking. I divided a color host image into blocks using mat2cell. i hid watermark images in respective blocks. i wanted to know how i can recombine the watermarked blocks? Dear sir,
I am working on Watermarking. I divided a color host image into blocks using mat2cell. i hid watermark images in respective blocks. i wanted to know how i can recombine the watermarked blocks? watermarking, mat2cell MATLAB Answers — New Questions
App Designer, tab-group : docking/ undocking/ closing possibilities
if there is a possibility to implement dock/undock/ close features for tabs when designing an app using app designer . These options are mainly for the user :
> right click on the top of the required tab and performed the desire options ( close / dock/ undock ) – otherwise the app gets overcrowded with too many tabs opened .if there is a possibility to implement dock/undock/ close features for tabs when designing an app using app designer . These options are mainly for the user :
> right click on the top of the required tab and performed the desire options ( close / dock/ undock ) – otherwise the app gets overcrowded with too many tabs opened . if there is a possibility to implement dock/undock/ close features for tabs when designing an app using app designer . These options are mainly for the user :
> right click on the top of the required tab and performed the desire options ( close / dock/ undock ) – otherwise the app gets overcrowded with too many tabs opened . app designer, uitab, uitabgroup, docking/undocking MATLAB Answers — New Questions
The Problem with clc; clear; close all; ?
A few days ago someone pointed out that using:
clc; clear; close all;
Is considered as a case of code smell and cargo cult programming.
But does that really have to be the case?
clc: cleans up the command window and now one can work without getting confused with the commands for previous runs
clear: erases the variables from previous runs this will reduce chances of error in subsequent runs and the programmer does not have to worry about unnecessary trash variables.
close all: closes all currently open figures. This can be very helpful during subsequent runs of the same script. If the figure from the previous run has not been closed then the subsequent run will plot the data on the already open figure. Which of course is a total waste.
What is the problem with using these commands?A few days ago someone pointed out that using:
clc; clear; close all;
Is considered as a case of code smell and cargo cult programming.
But does that really have to be the case?
clc: cleans up the command window and now one can work without getting confused with the commands for previous runs
clear: erases the variables from previous runs this will reduce chances of error in subsequent runs and the programmer does not have to worry about unnecessary trash variables.
close all: closes all currently open figures. This can be very helpful during subsequent runs of the same script. If the figure from the previous run has not been closed then the subsequent run will plot the data on the already open figure. Which of course is a total waste.
What is the problem with using these commands? A few days ago someone pointed out that using:
clc; clear; close all;
Is considered as a case of code smell and cargo cult programming.
But does that really have to be the case?
clc: cleans up the command window and now one can work without getting confused with the commands for previous runs
clear: erases the variables from previous runs this will reduce chances of error in subsequent runs and the programmer does not have to worry about unnecessary trash variables.
close all: closes all currently open figures. This can be very helpful during subsequent runs of the same script. If the figure from the previous run has not been closed then the subsequent run will plot the data on the already open figure. Which of course is a total waste.
What is the problem with using these commands? codesmell, cargocultprogramming, clc, clear, close all MATLAB Answers — New Questions
Finding series of values within array
Hi, I am up for a problem which I cannot totally solve.
Imagine I have an array: testtimes=[0.2 1.2 1.202 1.205 1.209 1.8 2.1 2.6 2.604 2.606 3.601 3.603 3.605];
Now I need to find all series of values where the difference between values is less than 0.01. So for now I did this:
if true
% code
end
% reference = 0.01
% isitesttimes=diff(testtimes); belowBIthreshold=(isitesttimes<reference);
% belowBIthreshold = [false, belowBIthreshold, false];
% edges = diff(belowBIthreshold);
% rising = find(edges==1); falling = find(edges==-1); spanWidth = falling – rising; wideEnough = spanWidth >= 3;
% startPos = rising(wideEnough);
% endPos = falling(wideEnough)-1;
% allInSpan = cell2mat(arrayfun(@(x,y) x:1:y, startPos, endPos, ‘uni’, false))
However, the answer now is
allInSpan = 2 3 4
Which means that on position 2,3,4 in testtimes the values are postioned which have a difference less than 0.01. However, the correct answer in this example would be 2,3,4,5 (since also position 5 has a difference of less than 0.01 compared to the one on position 4) (apart from that 8,9,10,11,12,13 should also be in the answer but that has to do (I guess) with the cut-off/Span-Width of 3).
Preferably I would get a variable which has per row the positions of the testtimes, so:
Answer = 2,3,4
8,9,10
11,12,13 (because between 10 and 11 there is more than 0.01 difference)
Can somebody help me out?
Regards
PS I know that there are more topics about this but I couldn’t find the one which specifically adressess this question.Hi, I am up for a problem which I cannot totally solve.
Imagine I have an array: testtimes=[0.2 1.2 1.202 1.205 1.209 1.8 2.1 2.6 2.604 2.606 3.601 3.603 3.605];
Now I need to find all series of values where the difference between values is less than 0.01. So for now I did this:
if true
% code
end
% reference = 0.01
% isitesttimes=diff(testtimes); belowBIthreshold=(isitesttimes<reference);
% belowBIthreshold = [false, belowBIthreshold, false];
% edges = diff(belowBIthreshold);
% rising = find(edges==1); falling = find(edges==-1); spanWidth = falling – rising; wideEnough = spanWidth >= 3;
% startPos = rising(wideEnough);
% endPos = falling(wideEnough)-1;
% allInSpan = cell2mat(arrayfun(@(x,y) x:1:y, startPos, endPos, ‘uni’, false))
However, the answer now is
allInSpan = 2 3 4
Which means that on position 2,3,4 in testtimes the values are postioned which have a difference less than 0.01. However, the correct answer in this example would be 2,3,4,5 (since also position 5 has a difference of less than 0.01 compared to the one on position 4) (apart from that 8,9,10,11,12,13 should also be in the answer but that has to do (I guess) with the cut-off/Span-Width of 3).
Preferably I would get a variable which has per row the positions of the testtimes, so:
Answer = 2,3,4
8,9,10
11,12,13 (because between 10 and 11 there is more than 0.01 difference)
Can somebody help me out?
Regards
PS I know that there are more topics about this but I couldn’t find the one which specifically adressess this question. Hi, I am up for a problem which I cannot totally solve.
Imagine I have an array: testtimes=[0.2 1.2 1.202 1.205 1.209 1.8 2.1 2.6 2.604 2.606 3.601 3.603 3.605];
Now I need to find all series of values where the difference between values is less than 0.01. So for now I did this:
if true
% code
end
% reference = 0.01
% isitesttimes=diff(testtimes); belowBIthreshold=(isitesttimes<reference);
% belowBIthreshold = [false, belowBIthreshold, false];
% edges = diff(belowBIthreshold);
% rising = find(edges==1); falling = find(edges==-1); spanWidth = falling – rising; wideEnough = spanWidth >= 3;
% startPos = rising(wideEnough);
% endPos = falling(wideEnough)-1;
% allInSpan = cell2mat(arrayfun(@(x,y) x:1:y, startPos, endPos, ‘uni’, false))
However, the answer now is
allInSpan = 2 3 4
Which means that on position 2,3,4 in testtimes the values are postioned which have a difference less than 0.01. However, the correct answer in this example would be 2,3,4,5 (since also position 5 has a difference of less than 0.01 compared to the one on position 4) (apart from that 8,9,10,11,12,13 should also be in the answer but that has to do (I guess) with the cut-off/Span-Width of 3).
Preferably I would get a variable which has per row the positions of the testtimes, so:
Answer = 2,3,4
8,9,10
11,12,13 (because between 10 and 11 there is more than 0.01 difference)
Can somebody help me out?
Regards
PS I know that there are more topics about this but I couldn’t find the one which specifically adressess this question. find MATLAB Answers — New Questions
Use Preelokup and n-Direct Lookup Table blocks in Simulink without interpolation
Hi,
I want to create a lookup table that based on some inputs, where the indeces of the lookup table are found and the field value is output.
I attach the lookup table I made with its corresponding breakpoints.
I am using two Preelokup blocks to find the indeces of this 2D table. These indices are used then as input to the Direct LookupTable block (see the attached block diagram picture).
My issue is that if I input e.g., 28 in "in1", the index found is correct. However, if I put a value within two breakpoint values (e.g., 30) it uses interpolation, flat or rounding, and I would like to avoid that. Is there a way where if the input value does not match with any of the breakpoints array it simply does not return any index or the Lookup table simply returns no value or a zero?
Thanks in advanceHi,
I want to create a lookup table that based on some inputs, where the indeces of the lookup table are found and the field value is output.
I attach the lookup table I made with its corresponding breakpoints.
I am using two Preelokup blocks to find the indeces of this 2D table. These indices are used then as input to the Direct LookupTable block (see the attached block diagram picture).
My issue is that if I input e.g., 28 in "in1", the index found is correct. However, if I put a value within two breakpoint values (e.g., 30) it uses interpolation, flat or rounding, and I would like to avoid that. Is there a way where if the input value does not match with any of the breakpoints array it simply does not return any index or the Lookup table simply returns no value or a zero?
Thanks in advance Hi,
I want to create a lookup table that based on some inputs, where the indeces of the lookup table are found and the field value is output.
I attach the lookup table I made with its corresponding breakpoints.
I am using two Preelokup blocks to find the indeces of this 2D table. These indices are used then as input to the Direct LookupTable block (see the attached block diagram picture).
My issue is that if I input e.g., 28 in "in1", the index found is correct. However, if I put a value within two breakpoint values (e.g., 30) it uses interpolation, flat or rounding, and I would like to avoid that. Is there a way where if the input value does not match with any of the breakpoints array it simply does not return any index or the Lookup table simply returns no value or a zero?
Thanks in advance simulink, lookuptable MATLAB Answers — New Questions