Month: January 2025
How to Configure your Student Competition License
How to Configure your Student Competition LicenseHow to Configure your Student Competition License How to Configure your Student Competition License student, competition MATLAB Answers — New Questions
How can I filter a FFt signal to only show the main frequency?
I have the following code (a sample data file is attached).
load("sample_signal.mat");
whos
figure
subplot(2,1,1)
hold on; grid minor
plot(signals.signal_01.signal)
plot(signals.signal_02.signal)
plot(signals.signal_03.time, signals.signal_03.theta, ‘k’)
title("Signal");
subplot(2,1,2)
hold on; grid minor
fs = 1;
[freq, amplitude, phase] = generic_fft(signals.signal_01.signal, fs);
plot(freq, amplitude)
[freq, amplitude, phase] = generic_fft(signals.signal_02.signal, fs);
plot(freq, amplitude)
fs = 10;
[freq, amplitude, phase] = generic_fft(signals.signal_03.theta, fs);
plot(freq, amplitude, ‘k’)
xlim([0 0.5])
xlabel("$omega$ [rad/s]")
ylabel("fft")
title("FFT");
% fft function
function [freq, amplitude, phase] = generic_fft(signal, fs)
% Remove NaNs
signal = signal(~isnan(signal));
% Length of the signal
n = length(signal);
% Perform FFT
fft_values = fft(signal);
% Compute single-sided amplitude spectrum
amplitude = abs(fft_values / n); % Normalize by length
amplitude = amplitude(1:floor(n / 2) + 1); % Keep positive frequencies
amplitude(2:end-1) = 2 * amplitude(2:end-1);
% Compute single-sided phase spectrum
phase = angle(fft_values(1:floor(n / 2) + 1));
% Frequency vector
freq = (0:(n / 2)) * (fs / n);
end
Now, the signal plotted in black shows a clear, dominant frequency in the FFt, but the other two signals show additional "noise" (see, after 0.1 rad/s). Is it possible to maybe filter these out or only show the dominant frequency?
The code is rough and the data structure is also not ideal (I saved the data mid-simulation for this question 🙂 ). Also, any tips to improve the fft function is also very appreciated. TIA!I have the following code (a sample data file is attached).
load("sample_signal.mat");
whos
figure
subplot(2,1,1)
hold on; grid minor
plot(signals.signal_01.signal)
plot(signals.signal_02.signal)
plot(signals.signal_03.time, signals.signal_03.theta, ‘k’)
title("Signal");
subplot(2,1,2)
hold on; grid minor
fs = 1;
[freq, amplitude, phase] = generic_fft(signals.signal_01.signal, fs);
plot(freq, amplitude)
[freq, amplitude, phase] = generic_fft(signals.signal_02.signal, fs);
plot(freq, amplitude)
fs = 10;
[freq, amplitude, phase] = generic_fft(signals.signal_03.theta, fs);
plot(freq, amplitude, ‘k’)
xlim([0 0.5])
xlabel("$omega$ [rad/s]")
ylabel("fft")
title("FFT");
% fft function
function [freq, amplitude, phase] = generic_fft(signal, fs)
% Remove NaNs
signal = signal(~isnan(signal));
% Length of the signal
n = length(signal);
% Perform FFT
fft_values = fft(signal);
% Compute single-sided amplitude spectrum
amplitude = abs(fft_values / n); % Normalize by length
amplitude = amplitude(1:floor(n / 2) + 1); % Keep positive frequencies
amplitude(2:end-1) = 2 * amplitude(2:end-1);
% Compute single-sided phase spectrum
phase = angle(fft_values(1:floor(n / 2) + 1));
% Frequency vector
freq = (0:(n / 2)) * (fs / n);
end
Now, the signal plotted in black shows a clear, dominant frequency in the FFt, but the other two signals show additional "noise" (see, after 0.1 rad/s). Is it possible to maybe filter these out or only show the dominant frequency?
The code is rough and the data structure is also not ideal (I saved the data mid-simulation for this question 🙂 ). Also, any tips to improve the fft function is also very appreciated. TIA! I have the following code (a sample data file is attached).
load("sample_signal.mat");
whos
figure
subplot(2,1,1)
hold on; grid minor
plot(signals.signal_01.signal)
plot(signals.signal_02.signal)
plot(signals.signal_03.time, signals.signal_03.theta, ‘k’)
title("Signal");
subplot(2,1,2)
hold on; grid minor
fs = 1;
[freq, amplitude, phase] = generic_fft(signals.signal_01.signal, fs);
plot(freq, amplitude)
[freq, amplitude, phase] = generic_fft(signals.signal_02.signal, fs);
plot(freq, amplitude)
fs = 10;
[freq, amplitude, phase] = generic_fft(signals.signal_03.theta, fs);
plot(freq, amplitude, ‘k’)
xlim([0 0.5])
xlabel("$omega$ [rad/s]")
ylabel("fft")
title("FFT");
% fft function
function [freq, amplitude, phase] = generic_fft(signal, fs)
% Remove NaNs
signal = signal(~isnan(signal));
% Length of the signal
n = length(signal);
% Perform FFT
fft_values = fft(signal);
% Compute single-sided amplitude spectrum
amplitude = abs(fft_values / n); % Normalize by length
amplitude = amplitude(1:floor(n / 2) + 1); % Keep positive frequencies
amplitude(2:end-1) = 2 * amplitude(2:end-1);
% Compute single-sided phase spectrum
phase = angle(fft_values(1:floor(n / 2) + 1));
% Frequency vector
freq = (0:(n / 2)) * (fs / n);
end
Now, the signal plotted in black shows a clear, dominant frequency in the FFt, but the other two signals show additional "noise" (see, after 0.1 rad/s). Is it possible to maybe filter these out or only show the dominant frequency?
The code is rough and the data structure is also not ideal (I saved the data mid-simulation for this question 🙂 ). Also, any tips to improve the fft function is also very appreciated. TIA! fft, filter, plot MATLAB Answers — New Questions
Errors encountered when implementing the code of “Train Voice Activity Detection in Noise Model Using Deep Learning”
Hello,I encountered an error while running the example code from the MathWorks tutorial "Train Voice Activity Detection in Noise Model Using Deep Learning". I am using MATLAB Online and did not modify the original code.The error occurs at line 150 when calling the trainnet function:
noisyvadnet = trainnet(XTrain, TTrain, net, "mse", options);
The error message is:
Error using trainnet (line 54)
Execution failed during layer(s) "cnn2.norm1".
Caused by:
Arrays have incompatible sizes for this operation.
Error in deep.internal.recording.operations.TimesBroadcastOp/forward (line 31)
x = x .* y;
^
Error in .* (line 39)
zdata = matlab.lang.internal.move(xdata) .* matlab.lang.internal.move(ydata);
^
Error in audio.ai.vadnet.layers.layerNormalizationElementwiseLayer/predict (line 59)
Z = layer.Scale.*Xn + layer.Bias;
^
Error in nnet.layer.Layer/forward (line 129)
[varargout{1:layer.NumOutputs+layer.PrivateNumStates}] = predict( layer, varargin{:} );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since many functions related to this error are read-only, I cannot insert debugging code to investigate further.Could you please help me understand why this error occurs and how to resolve it?Thank you!Hello,I encountered an error while running the example code from the MathWorks tutorial "Train Voice Activity Detection in Noise Model Using Deep Learning". I am using MATLAB Online and did not modify the original code.The error occurs at line 150 when calling the trainnet function:
noisyvadnet = trainnet(XTrain, TTrain, net, "mse", options);
The error message is:
Error using trainnet (line 54)
Execution failed during layer(s) "cnn2.norm1".
Caused by:
Arrays have incompatible sizes for this operation.
Error in deep.internal.recording.operations.TimesBroadcastOp/forward (line 31)
x = x .* y;
^
Error in .* (line 39)
zdata = matlab.lang.internal.move(xdata) .* matlab.lang.internal.move(ydata);
^
Error in audio.ai.vadnet.layers.layerNormalizationElementwiseLayer/predict (line 59)
Z = layer.Scale.*Xn + layer.Bias;
^
Error in nnet.layer.Layer/forward (line 129)
[varargout{1:layer.NumOutputs+layer.PrivateNumStates}] = predict( layer, varargin{:} );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since many functions related to this error are read-only, I cannot insert debugging code to investigate further.Could you please help me understand why this error occurs and how to resolve it?Thank you! Hello,I encountered an error while running the example code from the MathWorks tutorial "Train Voice Activity Detection in Noise Model Using Deep Learning". I am using MATLAB Online and did not modify the original code.The error occurs at line 150 when calling the trainnet function:
noisyvadnet = trainnet(XTrain, TTrain, net, "mse", options);
The error message is:
Error using trainnet (line 54)
Execution failed during layer(s) "cnn2.norm1".
Caused by:
Arrays have incompatible sizes for this operation.
Error in deep.internal.recording.operations.TimesBroadcastOp/forward (line 31)
x = x .* y;
^
Error in .* (line 39)
zdata = matlab.lang.internal.move(xdata) .* matlab.lang.internal.move(ydata);
^
Error in audio.ai.vadnet.layers.layerNormalizationElementwiseLayer/predict (line 59)
Z = layer.Scale.*Xn + layer.Bias;
^
Error in nnet.layer.Layer/forward (line 129)
[varargout{1:layer.NumOutputs+layer.PrivateNumStates}] = predict( layer, varargin{:} );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since many functions related to this error are read-only, I cannot insert debugging code to investigate further.Could you please help me understand why this error occurs and how to resolve it?Thank you! incompatible sizes, tutorial code MATLAB Answers — New Questions
MINLP problem in MATLAB with both integer constraints and nonlinear equality constraints
Knowing that: “When there are integer constraints, ga and gamultiobj do not accept nonlinear equality constraints, only nonlinear inequality constraints.”, How do you solve MINLP problems of the following form in MATLAB?Knowing that: “When there are integer constraints, ga and gamultiobj do not accept nonlinear equality constraints, only nonlinear inequality constraints.”, How do you solve MINLP problems of the following form in MATLAB? Knowing that: “When there are integer constraints, ga and gamultiobj do not accept nonlinear equality constraints, only nonlinear inequality constraints.”, How do you solve MINLP problems of the following form in MATLAB? minlp MATLAB Answers — New Questions
Configuration of ROS Toolbox through CLI?
Hello everyone,
my main question is in the title. For reference, I want to create a docker container running matlab to generate some standalone ROS2 nodes. This works fine until I have to set the path to the Python-executable. It seems to be only possible through the GUI. Am I mistaken here and is there maybe a way to set the executable and create the venv via CLI commands?
Best regards,
SönkeHello everyone,
my main question is in the title. For reference, I want to create a docker container running matlab to generate some standalone ROS2 nodes. This works fine until I have to set the path to the Python-executable. It seems to be only possible through the GUI. Am I mistaken here and is there maybe a way to set the executable and create the venv via CLI commands?
Best regards,
Sönke Hello everyone,
my main question is in the title. For reference, I want to create a docker container running matlab to generate some standalone ROS2 nodes. This works fine until I have to set the path to the Python-executable. It seems to be only possible through the GUI. Am I mistaken here and is there maybe a way to set the executable and create the venv via CLI commands?
Best regards,
Sönke ros2, cli, container, docker MATLAB Answers — New Questions
Is it possible to export Tool-coupling FMU from Simulink model with compiled MEX S function? [r2019b]
hi, i try to export a FMU from Simulink model in which has a compiled MEX S function. I import the generated FMU to Simulink and it could not run successfully.
Is this only possible to export FMU with white box model?
Thanks in advance.hi, i try to export a FMU from Simulink model in which has a compiled MEX S function. I import the generated FMU to Simulink and it could not run successfully.
Is this only possible to export FMU with white box model?
Thanks in advance. hi, i try to export a FMU from Simulink model in which has a compiled MEX S function. I import the generated FMU to Simulink and it could not run successfully.
Is this only possible to export FMU with white box model?
Thanks in advance. fmu export MATLAB Answers — New Questions
Class Property Validation for the Contents of a Cell Array Property?
I’m writing a class that stores its data in the form of cell arrays, matching values to their units. An example property definition might look something like:
classdef myClass
properties (SetAccess = private)
prop1 (2, 2) cell = { 1000, "m" ; 1, "km" }
end
end
In the class definition, I’d like to use property validation to restrict the values in column 1 to valid distances, nonnegative for example, and column 2 to valid strings that define an actual unit type, "m"/"ft"/"in" for example. This is trivial for defined types, like ‘int16’ or ‘double’, but I’m wondering if anyone has accomplished this for columns/rows inside a cell array. The goal here is to store property value with its unit, while also restricting both to valid input. Is this possible given the cell type at property definition? Thanks!I’m writing a class that stores its data in the form of cell arrays, matching values to their units. An example property definition might look something like:
classdef myClass
properties (SetAccess = private)
prop1 (2, 2) cell = { 1000, "m" ; 1, "km" }
end
end
In the class definition, I’d like to use property validation to restrict the values in column 1 to valid distances, nonnegative for example, and column 2 to valid strings that define an actual unit type, "m"/"ft"/"in" for example. This is trivial for defined types, like ‘int16’ or ‘double’, but I’m wondering if anyone has accomplished this for columns/rows inside a cell array. The goal here is to store property value with its unit, while also restricting both to valid input. Is this possible given the cell type at property definition? Thanks! I’m writing a class that stores its data in the form of cell arrays, matching values to their units. An example property definition might look something like:
classdef myClass
properties (SetAccess = private)
prop1 (2, 2) cell = { 1000, "m" ; 1, "km" }
end
end
In the class definition, I’d like to use property validation to restrict the values in column 1 to valid distances, nonnegative for example, and column 2 to valid strings that define an actual unit type, "m"/"ft"/"in" for example. This is trivial for defined types, like ‘int16’ or ‘double’, but I’m wondering if anyone has accomplished this for columns/rows inside a cell array. The goal here is to store property value with its unit, while also restricting both to valid input. Is this possible given the cell type at property definition? Thanks! cell arrays, property validation MATLAB Answers — New Questions
Simulink Raspberry Code Generation Running Very Slow
I am trying to compile a simple gpio trigger signal that I created with Simulink and run it on the raspberry. But unfortunately, when I measure with an oscilloscope from the gpio pin, which should trigger 2khz, I see a 2hz measurement. I would appreciate if you can help with this. It is interesting that even *very simple models* have such problems. (Matlab2024a)I am trying to compile a simple gpio trigger signal that I created with Simulink and run it on the raspberry. But unfortunately, when I measure with an oscilloscope from the gpio pin, which should trigger 2khz, I see a 2hz measurement. I would appreciate if you can help with this. It is interesting that even *very simple models* have such problems. (Matlab2024a) I am trying to compile a simple gpio trigger signal that I created with Simulink and run it on the raspberry. But unfortunately, when I measure with an oscilloscope from the gpio pin, which should trigger 2khz, I see a 2hz measurement. I would appreciate if you can help with this. It is interesting that even *very simple models* have such problems. (Matlab2024a) simulink, code generation MATLAB Answers — New Questions
Simulink model deployed in Raspberry Pi is not running in Real-time
I have a simulink model for grid connected PV system. In that model Modbus Slave write blocks are used to store all the power system network measurements, so that these values can be read from other Modbus master device.
The model is successfully built and gets deployed on Raspi with out any errors. I could read the values from another modbus mater. However, the model is running very slowly, and it tooks minutes to reach to the state of 1 sec in simulation.
Please help me, How can I solve this issue.I have a simulink model for grid connected PV system. In that model Modbus Slave write blocks are used to store all the power system network measurements, so that these values can be read from other Modbus master device.
The model is successfully built and gets deployed on Raspi with out any errors. I could read the values from another modbus mater. However, the model is running very slowly, and it tooks minutes to reach to the state of 1 sec in simulation.
Please help me, How can I solve this issue. I have a simulink model for grid connected PV system. In that model Modbus Slave write blocks are used to store all the power system network measurements, so that these values can be read from other Modbus master device.
The model is successfully built and gets deployed on Raspi with out any errors. I could read the values from another modbus mater. However, the model is running very slowly, and it tooks minutes to reach to the state of 1 sec in simulation.
Please help me, How can I solve this issue. simulink interface with raspberry pi MATLAB Answers — New Questions
Can Simulink Models Be Ran On A GPU?
I’m part of a group trying to speed up our code. We send out inputs to the simulink model with
simIn(i) = simIn(i).setVariable(‘Amplitude’, pops(i, 1));
simIn(i) = simIn(i).setVariable(‘Freq’, pops(i, 2));
simIn(i) = simIn(i).setVariable(‘PW’, pops(i, 3));
simIn(i) = simIn(i).setVariable(‘Ramp_Toggle’, pops(i, 4));
simIn(i) = simIn(i).setVariable(‘Ramp_Slope’, pops(i, 5));
simIn(i) = simIn(i).setVariable(‘Ramp_Flat’, pops(i, 6));
simIn(i) = simIn(i).setVariable(‘Intraburst_Toggle’, pops(i, 7));
simIn(i) = simIn(i).setVariable(‘Intraburst_Period’, pops(i, 8));
simIn(i) = simIn(i).setVariable(‘Intraburst_Packet’, pops(i, 9));
simIn(i) = simIn(i).setVariable(‘Phasic’, pops(i, 10));
and take back outputs with
simOut = parsim(simIn, ‘ShowSimulationManager’, ‘off’);
Using tic toc it seems that the simulink model takes about 90% of our runtime. Is there a way to run this on the GPU or other ways to speed it up? Any help will be greatly appreciated.
Thank youI’m part of a group trying to speed up our code. We send out inputs to the simulink model with
simIn(i) = simIn(i).setVariable(‘Amplitude’, pops(i, 1));
simIn(i) = simIn(i).setVariable(‘Freq’, pops(i, 2));
simIn(i) = simIn(i).setVariable(‘PW’, pops(i, 3));
simIn(i) = simIn(i).setVariable(‘Ramp_Toggle’, pops(i, 4));
simIn(i) = simIn(i).setVariable(‘Ramp_Slope’, pops(i, 5));
simIn(i) = simIn(i).setVariable(‘Ramp_Flat’, pops(i, 6));
simIn(i) = simIn(i).setVariable(‘Intraburst_Toggle’, pops(i, 7));
simIn(i) = simIn(i).setVariable(‘Intraburst_Period’, pops(i, 8));
simIn(i) = simIn(i).setVariable(‘Intraburst_Packet’, pops(i, 9));
simIn(i) = simIn(i).setVariable(‘Phasic’, pops(i, 10));
and take back outputs with
simOut = parsim(simIn, ‘ShowSimulationManager’, ‘off’);
Using tic toc it seems that the simulink model takes about 90% of our runtime. Is there a way to run this on the GPU or other ways to speed it up? Any help will be greatly appreciated.
Thank you I’m part of a group trying to speed up our code. We send out inputs to the simulink model with
simIn(i) = simIn(i).setVariable(‘Amplitude’, pops(i, 1));
simIn(i) = simIn(i).setVariable(‘Freq’, pops(i, 2));
simIn(i) = simIn(i).setVariable(‘PW’, pops(i, 3));
simIn(i) = simIn(i).setVariable(‘Ramp_Toggle’, pops(i, 4));
simIn(i) = simIn(i).setVariable(‘Ramp_Slope’, pops(i, 5));
simIn(i) = simIn(i).setVariable(‘Ramp_Flat’, pops(i, 6));
simIn(i) = simIn(i).setVariable(‘Intraburst_Toggle’, pops(i, 7));
simIn(i) = simIn(i).setVariable(‘Intraburst_Period’, pops(i, 8));
simIn(i) = simIn(i).setVariable(‘Intraburst_Packet’, pops(i, 9));
simIn(i) = simIn(i).setVariable(‘Phasic’, pops(i, 10));
and take back outputs with
simOut = parsim(simIn, ‘ShowSimulationManager’, ‘off’);
Using tic toc it seems that the simulink model takes about 90% of our runtime. Is there a way to run this on the GPU or other ways to speed it up? Any help will be greatly appreciated.
Thank you simulink, gpu MATLAB Answers — New Questions
¿Porque no corre mi código? No aparece nada
Le pongo en correr y no pasa nadaLe pongo en correr y no pasa nada Le pongo en correr y no pasa nada codigo MATLAB Answers — New Questions
Can a PWM signal with a 100% duty cycle be considered as an unit step?
I am working on the temperature control of an electric oven. I had the idea of obtaining the temperature-time curve when the oven is fed with the alternating wave at maximum power (220 V 60 Hz). According to the Ziegler-Nichols tuning method, my curve would be the response of the system (oven) to a "unit step". But here I have a doubt. To control the power, I am using a BT136 triac, which receives a 5 volt PWM wave at its gate. When this 5 volt PWM signal is at 100% duty cycle, could I consider it as a unit step?
Thanks in advance for your attentionI am working on the temperature control of an electric oven. I had the idea of obtaining the temperature-time curve when the oven is fed with the alternating wave at maximum power (220 V 60 Hz). According to the Ziegler-Nichols tuning method, my curve would be the response of the system (oven) to a "unit step". But here I have a doubt. To control the power, I am using a BT136 triac, which receives a 5 volt PWM wave at its gate. When this 5 volt PWM signal is at 100% duty cycle, could I consider it as a unit step?
Thanks in advance for your attention I am working on the temperature control of an electric oven. I had the idea of obtaining the temperature-time curve when the oven is fed with the alternating wave at maximum power (220 V 60 Hz). According to the Ziegler-Nichols tuning method, my curve would be the response of the system (oven) to a "unit step". But here I have a doubt. To control the power, I am using a BT136 triac, which receives a 5 volt PWM wave at its gate. When this 5 volt PWM signal is at 100% duty cycle, could I consider it as a unit step?
Thanks in advance for your attention control, unit step, pwm MATLAB Answers — New Questions
Error using sub2ind: out of range subscript
Hi,
I am running a matlab gui and when I load the data (multitiff file) and display it in the axes I get the following error. I don’t know how to proceed because the error doesn’t appear every time I run the code. I tried to check which version of sub2ind maltab is using and it seems to use the correct version. Thank you in advance for your help.
Warning: Error occurred while executing the listener callback for event Action defined for class
matlab.graphics.interaction.graphicscontrol.AxesControl:
Error using sub2ind
Out of range subscript.
Error in matlab.graphics.chart.interaction.dataannotatable.ImageAdaptor/getNearestImageIndex (line 369)
index = sub2ind(dataSize, nRC(1), nRC(2));
Error in matlab.graphics.chart.interaction.dataannotatable.ImageAdaptor/doGetNearestPoint (line 225)
index = getNearestImageIndex(hObj, point_v, basis_row, basis_col);
Error in matlab.graphics.interaction.uiaxes.DataTipsBase
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipHoverLingerInteraction/handleEvent
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipBaseInteraction/response
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.InteractionBase/responseevent
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.InteractionBase
Error in matlab.graphics.interaction.graphicscontrol.GenericControl/process
Error in matlab.graphics.interaction.graphicscontrol.layoutable.LayoutableControl/process
Error in matlab.graphics.interaction.graphicscontrol.layoutable.GridLayoutableControl/process
Error in matlab.graphics.interaction.graphicscontrol.AxesControl/process
Error in matlab.graphics.interaction.graphicscontrol.ControlManager/processMessage
> In matlab.graphics.interaction.graphicscontrol/GenericControl/process
In matlab.graphics.interaction.graphicscontrol.layoutable/LayoutableControl/process
In matlab.graphics.interaction.graphicscontrol.layoutable/GridLayoutableControl/process
In matlab.graphics.interaction.graphicscontrol/AxesControl/process
In matlab.graphics.interaction.graphicscontrol/ControlManager/processMessageHi,
I am running a matlab gui and when I load the data (multitiff file) and display it in the axes I get the following error. I don’t know how to proceed because the error doesn’t appear every time I run the code. I tried to check which version of sub2ind maltab is using and it seems to use the correct version. Thank you in advance for your help.
Warning: Error occurred while executing the listener callback for event Action defined for class
matlab.graphics.interaction.graphicscontrol.AxesControl:
Error using sub2ind
Out of range subscript.
Error in matlab.graphics.chart.interaction.dataannotatable.ImageAdaptor/getNearestImageIndex (line 369)
index = sub2ind(dataSize, nRC(1), nRC(2));
Error in matlab.graphics.chart.interaction.dataannotatable.ImageAdaptor/doGetNearestPoint (line 225)
index = getNearestImageIndex(hObj, point_v, basis_row, basis_col);
Error in matlab.graphics.interaction.uiaxes.DataTipsBase
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipHoverLingerInteraction/handleEvent
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipBaseInteraction/response
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.InteractionBase/responseevent
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.InteractionBase
Error in matlab.graphics.interaction.graphicscontrol.GenericControl/process
Error in matlab.graphics.interaction.graphicscontrol.layoutable.LayoutableControl/process
Error in matlab.graphics.interaction.graphicscontrol.layoutable.GridLayoutableControl/process
Error in matlab.graphics.interaction.graphicscontrol.AxesControl/process
Error in matlab.graphics.interaction.graphicscontrol.ControlManager/processMessage
> In matlab.graphics.interaction.graphicscontrol/GenericControl/process
In matlab.graphics.interaction.graphicscontrol.layoutable/LayoutableControl/process
In matlab.graphics.interaction.graphicscontrol.layoutable/GridLayoutableControl/process
In matlab.graphics.interaction.graphicscontrol/AxesControl/process
In matlab.graphics.interaction.graphicscontrol/ControlManager/processMessage Hi,
I am running a matlab gui and when I load the data (multitiff file) and display it in the axes I get the following error. I don’t know how to proceed because the error doesn’t appear every time I run the code. I tried to check which version of sub2ind maltab is using and it seems to use the correct version. Thank you in advance for your help.
Warning: Error occurred while executing the listener callback for event Action defined for class
matlab.graphics.interaction.graphicscontrol.AxesControl:
Error using sub2ind
Out of range subscript.
Error in matlab.graphics.chart.interaction.dataannotatable.ImageAdaptor/getNearestImageIndex (line 369)
index = sub2ind(dataSize, nRC(1), nRC(2));
Error in matlab.graphics.chart.interaction.dataannotatable.ImageAdaptor/doGetNearestPoint (line 225)
index = getNearestImageIndex(hObj, point_v, basis_row, basis_col);
Error in matlab.graphics.interaction.uiaxes.DataTipsBase
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipHoverLingerInteraction/handleEvent
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipBaseInteraction/response
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.InteractionBase/responseevent
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.InteractionBase
Error in matlab.graphics.interaction.graphicscontrol.GenericControl/process
Error in matlab.graphics.interaction.graphicscontrol.layoutable.LayoutableControl/process
Error in matlab.graphics.interaction.graphicscontrol.layoutable.GridLayoutableControl/process
Error in matlab.graphics.interaction.graphicscontrol.AxesControl/process
Error in matlab.graphics.interaction.graphicscontrol.ControlManager/processMessage
> In matlab.graphics.interaction.graphicscontrol/GenericControl/process
In matlab.graphics.interaction.graphicscontrol.layoutable/LayoutableControl/process
In matlab.graphics.interaction.graphicscontrol.layoutable/GridLayoutableControl/process
In matlab.graphics.interaction.graphicscontrol/AxesControl/process
In matlab.graphics.interaction.graphicscontrol/ControlManager/processMessage gui, axes MATLAB Answers — New Questions
Questions about the switching losses of a MOSFET
Using Simulink for circuit simulation of a PMSM system, with a focus on MOSFET losses in the inverter circuit.
MOSFET (Ideal, Switching), PS signal controlled. The thermal port is connected to a 25°C constant temperature source.
According to the simulation results, three-phase currents, motor torque and speed are consistent with the expected values.
Q1. The MOSFET switching losses exist only during positive current, and they disappear during negative current. Should switching losses exist only during positive current?
Q2. The fixed switch loss value set in the “MOSFET (Ideal, Switching)” module is 3e-5 J. However, the simulation results show fluctuations around this value with respect to the Id current. What is the specific relationship between the fixed switch loss value and the fluctuating simulation resultsUsing Simulink for circuit simulation of a PMSM system, with a focus on MOSFET losses in the inverter circuit.
MOSFET (Ideal, Switching), PS signal controlled. The thermal port is connected to a 25°C constant temperature source.
According to the simulation results, three-phase currents, motor torque and speed are consistent with the expected values.
Q1. The MOSFET switching losses exist only during positive current, and they disappear during negative current. Should switching losses exist only during positive current?
Q2. The fixed switch loss value set in the “MOSFET (Ideal, Switching)” module is 3e-5 J. However, the simulation results show fluctuations around this value with respect to the Id current. What is the specific relationship between the fixed switch loss value and the fluctuating simulation results Using Simulink for circuit simulation of a PMSM system, with a focus on MOSFET losses in the inverter circuit.
MOSFET (Ideal, Switching), PS signal controlled. The thermal port is connected to a 25°C constant temperature source.
According to the simulation results, three-phase currents, motor torque and speed are consistent with the expected values.
Q1. The MOSFET switching losses exist only during positive current, and they disappear during negative current. Should switching losses exist only during positive current?
Q2. The fixed switch loss value set in the “MOSFET (Ideal, Switching)” module is 3e-5 J. However, the simulation results show fluctuations around this value with respect to the Id current. What is the specific relationship between the fixed switch loss value and the fluctuating simulation results simscape, simulink, mosfet, pmsm MATLAB Answers — New Questions
parallel computing apply to my problem
clc;
clear all;
close all;
tic;
N=10;
a=zeros(1,N+1);
b=zeros(1,N+1);
syms t a b
a(1)=2;b(1)=-3;
for i=1:7
v1=(a(i)*t+5*a(i)*t^2+30*b(i)*t);
v2=(b(i)*t-20*b(i)*t^3+30*a(i)*b(i)*t);
a(i+1)=diff(v1,t);
b(i+1)=diff(v2,t);
end
toc
fplot(v1,[0 0.1],’b’);
;;;i want to go for loop till 250 for above kind of problem when there are 8 equations means v1,v2…v8.it is taking so much of time and sometimes matlab is not responding.Please help me how can i wrote that proble with parallel computing or any some other simple programmimgclc;
clear all;
close all;
tic;
N=10;
a=zeros(1,N+1);
b=zeros(1,N+1);
syms t a b
a(1)=2;b(1)=-3;
for i=1:7
v1=(a(i)*t+5*a(i)*t^2+30*b(i)*t);
v2=(b(i)*t-20*b(i)*t^3+30*a(i)*b(i)*t);
a(i+1)=diff(v1,t);
b(i+1)=diff(v2,t);
end
toc
fplot(v1,[0 0.1],’b’);
;;;i want to go for loop till 250 for above kind of problem when there are 8 equations means v1,v2…v8.it is taking so much of time and sometimes matlab is not responding.Please help me how can i wrote that proble with parallel computing or any some other simple programmimg clc;
clear all;
close all;
tic;
N=10;
a=zeros(1,N+1);
b=zeros(1,N+1);
syms t a b
a(1)=2;b(1)=-3;
for i=1:7
v1=(a(i)*t+5*a(i)*t^2+30*b(i)*t);
v2=(b(i)*t-20*b(i)*t^3+30*a(i)*b(i)*t);
a(i+1)=diff(v1,t);
b(i+1)=diff(v2,t);
end
toc
fplot(v1,[0 0.1],’b’);
;;;i want to go for loop till 250 for above kind of problem when there are 8 equations means v1,v2…v8.it is taking so much of time and sometimes matlab is not responding.Please help me how can i wrote that proble with parallel computing or any some other simple programmimg parallel computing, syms MATLAB Answers — New Questions
How to plot a string signal/array?
Hi all,
In Simulink, I’m using String Signals to represent internal states for my systems. For example:
mySignal is a string signal, and not a numeric one. I log it into the base workspace inside the simout variable, and I also send it to the Simulation Data Inspector.
Inside the Simulation Data Inspector, this string signal is neatly displayed, like this :
The string values are displayed as colored patches, evolving with the simulation time.
This visualization method for string signals is great, but I can’t find a way to do something similar in MATLAB. Once my string signal is inside a base workspace variable, I try to plot it just like a regular signal, but it doesn’t work:
>> simout
simout =
struct with fields:
time: [1001×1 double]
signals: [1×1 struct]
blockName: ‘plot_string_signals/To Workspace’
>> simout.signals
ans =
struct with fields:
values: [1001×1 string]
dimensions: 1
label: ‘mySignal’
>> plot(simout.time, simout.signals.values)
Error using plot
Invalid data argument.
So my question is: how to plot a string datatype signal/array in MATLAB? Is there a dedicated plotting function for this use case that I don’t know ? I expected the plot function to provide the same kind of graph as the Simulation Data Inspector, but was disappointed.
(I’m using MATLAB 22b Update 8)
Thanks,
SeiganHi all,
In Simulink, I’m using String Signals to represent internal states for my systems. For example:
mySignal is a string signal, and not a numeric one. I log it into the base workspace inside the simout variable, and I also send it to the Simulation Data Inspector.
Inside the Simulation Data Inspector, this string signal is neatly displayed, like this :
The string values are displayed as colored patches, evolving with the simulation time.
This visualization method for string signals is great, but I can’t find a way to do something similar in MATLAB. Once my string signal is inside a base workspace variable, I try to plot it just like a regular signal, but it doesn’t work:
>> simout
simout =
struct with fields:
time: [1001×1 double]
signals: [1×1 struct]
blockName: ‘plot_string_signals/To Workspace’
>> simout.signals
ans =
struct with fields:
values: [1001×1 string]
dimensions: 1
label: ‘mySignal’
>> plot(simout.time, simout.signals.values)
Error using plot
Invalid data argument.
So my question is: how to plot a string datatype signal/array in MATLAB? Is there a dedicated plotting function for this use case that I don’t know ? I expected the plot function to provide the same kind of graph as the Simulation Data Inspector, but was disappointed.
(I’m using MATLAB 22b Update 8)
Thanks,
Seigan Hi all,
In Simulink, I’m using String Signals to represent internal states for my systems. For example:
mySignal is a string signal, and not a numeric one. I log it into the base workspace inside the simout variable, and I also send it to the Simulation Data Inspector.
Inside the Simulation Data Inspector, this string signal is neatly displayed, like this :
The string values are displayed as colored patches, evolving with the simulation time.
This visualization method for string signals is great, but I can’t find a way to do something similar in MATLAB. Once my string signal is inside a base workspace variable, I try to plot it just like a regular signal, but it doesn’t work:
>> simout
simout =
struct with fields:
time: [1001×1 double]
signals: [1×1 struct]
blockName: ‘plot_string_signals/To Workspace’
>> simout.signals
ans =
struct with fields:
values: [1001×1 string]
dimensions: 1
label: ‘mySignal’
>> plot(simout.time, simout.signals.values)
Error using plot
Invalid data argument.
So my question is: how to plot a string datatype signal/array in MATLAB? Is there a dedicated plotting function for this use case that I don’t know ? I expected the plot function to provide the same kind of graph as the Simulation Data Inspector, but was disappointed.
(I’m using MATLAB 22b Update 8)
Thanks,
Seigan plot, string MATLAB Answers — New Questions
How to connect ESP32-C3-ZERO to Simulink
Dear Users.
I hope that you are doing well,
I have one simple question on how to use ESP32-C3-ZERO on simulink is there any idea beside of using waijung?
My application is just to use wifi to read an analog signal.Dear Users.
I hope that you are doing well,
I have one simple question on how to use ESP32-C3-ZERO on simulink is there any idea beside of using waijung?
My application is just to use wifi to read an analog signal. Dear Users.
I hope that you are doing well,
I have one simple question on how to use ESP32-C3-ZERO on simulink is there any idea beside of using waijung?
My application is just to use wifi to read an analog signal. simulink, real-time-monitoring, esp32, arduino, signal MATLAB Answers — New Questions
Issue in creation of test harness of a Simulink state in stateflow or creation of harness of a subsystem present in simulink state of stateflow.
Hello,
I wish to create a harness of a simulink state present in a stateflow.I am not getting the option of ‘Test Harness’,when right clicked on state
Also i tried to create a harness of a subsystem present in that simulink state but got the following error
So is there any other way to create test harness of such simulink state or subsystem present in that simulink state?
If not then can you suggest how to test such state by creating test hanress?Hello,
I wish to create a harness of a simulink state present in a stateflow.I am not getting the option of ‘Test Harness’,when right clicked on state
Also i tried to create a harness of a subsystem present in that simulink state but got the following error
So is there any other way to create test harness of such simulink state or subsystem present in that simulink state?
If not then can you suggest how to test such state by creating test hanress? Hello,
I wish to create a harness of a simulink state present in a stateflow.I am not getting the option of ‘Test Harness’,when right clicked on state
Also i tried to create a harness of a subsystem present in that simulink state but got the following error
So is there any other way to create test harness of such simulink state or subsystem present in that simulink state?
If not then can you suggest how to test such state by creating test hanress? simulink, stateflow, simulinkstate, modelinloop, testharness, harness, error, states MATLAB Answers — New Questions
mean function gives an error but not median
I am trying to calculate mean, median and 90% percentile of arrays. Median and prctile work fine but mean gives an error message:
Array indices must be positive integers or logical values.
Teh error comes from Averted_Deaths_Array(ij,1) = mean(Averted_Deaths(ij,:)); in the following code.
The code is simple.
TotalDeathsArray = rand(12,2500);
% Calculate Averted cases
for i=1:2500
%2: PCV13 1+1, 3: PCV15 2+1, 4: PCV15 1+1
% 1+1
Averted_Deaths(1,i) = TotalDeathsArray(2,i) – TotalDeathsArray(4,i);
Averted_Deaths(2,i) = TotalDeathsArray(6,i) – TotalDeathsArray(8,i);
Averted_Deaths(3,i) = TotalDeathsArray(10,i) – TotalDeathsArray(12,i);
% 2+1
Averted_Deaths(4,i) = TotalDeathsArray(2,i) – TotalDeathsArray(3,i);
Averted_Deaths(5,i) = TotalDeathsArray(6,i) – TotalDeathsArray(7,i);
Averted_Deaths(6,i) = TotalDeathsArray(10,i) – TotalDeathsArray(11,i);
end
Averted_Deaths_Array = zeros(6,3);
for ij=1:6 % Averted QALY
%Averted QALY when changing with New 1+1
Averted_Deaths_Array(ij,1) = mean(Averted_Deaths(ij,:));
Averted_Deaths_Array(ij,2) = median(Averted_Deaths(ij,:));
Averted_Deaths_Array(ij,3) = prctile(Averted_Deaths(ij,:),90);
endI am trying to calculate mean, median and 90% percentile of arrays. Median and prctile work fine but mean gives an error message:
Array indices must be positive integers or logical values.
Teh error comes from Averted_Deaths_Array(ij,1) = mean(Averted_Deaths(ij,:)); in the following code.
The code is simple.
TotalDeathsArray = rand(12,2500);
% Calculate Averted cases
for i=1:2500
%2: PCV13 1+1, 3: PCV15 2+1, 4: PCV15 1+1
% 1+1
Averted_Deaths(1,i) = TotalDeathsArray(2,i) – TotalDeathsArray(4,i);
Averted_Deaths(2,i) = TotalDeathsArray(6,i) – TotalDeathsArray(8,i);
Averted_Deaths(3,i) = TotalDeathsArray(10,i) – TotalDeathsArray(12,i);
% 2+1
Averted_Deaths(4,i) = TotalDeathsArray(2,i) – TotalDeathsArray(3,i);
Averted_Deaths(5,i) = TotalDeathsArray(6,i) – TotalDeathsArray(7,i);
Averted_Deaths(6,i) = TotalDeathsArray(10,i) – TotalDeathsArray(11,i);
end
Averted_Deaths_Array = zeros(6,3);
for ij=1:6 % Averted QALY
%Averted QALY when changing with New 1+1
Averted_Deaths_Array(ij,1) = mean(Averted_Deaths(ij,:));
Averted_Deaths_Array(ij,2) = median(Averted_Deaths(ij,:));
Averted_Deaths_Array(ij,3) = prctile(Averted_Deaths(ij,:),90);
end I am trying to calculate mean, median and 90% percentile of arrays. Median and prctile work fine but mean gives an error message:
Array indices must be positive integers or logical values.
Teh error comes from Averted_Deaths_Array(ij,1) = mean(Averted_Deaths(ij,:)); in the following code.
The code is simple.
TotalDeathsArray = rand(12,2500);
% Calculate Averted cases
for i=1:2500
%2: PCV13 1+1, 3: PCV15 2+1, 4: PCV15 1+1
% 1+1
Averted_Deaths(1,i) = TotalDeathsArray(2,i) – TotalDeathsArray(4,i);
Averted_Deaths(2,i) = TotalDeathsArray(6,i) – TotalDeathsArray(8,i);
Averted_Deaths(3,i) = TotalDeathsArray(10,i) – TotalDeathsArray(12,i);
% 2+1
Averted_Deaths(4,i) = TotalDeathsArray(2,i) – TotalDeathsArray(3,i);
Averted_Deaths(5,i) = TotalDeathsArray(6,i) – TotalDeathsArray(7,i);
Averted_Deaths(6,i) = TotalDeathsArray(10,i) – TotalDeathsArray(11,i);
end
Averted_Deaths_Array = zeros(6,3);
for ij=1:6 % Averted QALY
%Averted QALY when changing with New 1+1
Averted_Deaths_Array(ij,1) = mean(Averted_Deaths(ij,:));
Averted_Deaths_Array(ij,2) = median(Averted_Deaths(ij,:));
Averted_Deaths_Array(ij,3) = prctile(Averted_Deaths(ij,:),90);
end mean function error MATLAB Answers — New Questions
Why is the torque in the torque sensor converging to zero
I’m doing a simulation using the pmsm library and switching elements. I want to know why 0 comes out in the trq scope. 1000 rpm is inputted at a fixed rate using an internal velocity source, and the three-phase current from the switching is outputted normally. The control part id iq is indicated as 0 100, and the id iq calculated from the three phases is also 0 100. How can I solve the problem that the torque converges to zero.I’m doing a simulation using the pmsm library and switching elements. I want to know why 0 comes out in the trq scope. 1000 rpm is inputted at a fixed rate using an internal velocity source, and the three-phase current from the switching is outputted normally. The control part id iq is indicated as 0 100, and the id iq calculated from the three phases is also 0 100. How can I solve the problem that the torque converges to zero. I’m doing a simulation using the pmsm library and switching elements. I want to know why 0 comes out in the trq scope. 1000 rpm is inputted at a fixed rate using an internal velocity source, and the three-phase current from the switching is outputted normally. The control part id iq is indicated as 0 100, and the id iq calculated from the three phases is also 0 100. How can I solve the problem that the torque converges to zero. pmsm MATLAB Answers — New Questions