Category: Matlab
Category Archives: Matlab
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
Hello, can MATLAB solve equations like the one below? I mean, can MATLAB find the conditions for z that satisfy this relationship, instead of just numerical solutions?
Post Content Post Content equation, mathematical MATLAB Answers — New Questions
Simulating on-grid three-phase inverter with SVPWM, but the alpha beta components diverge so much
I am simulating for on grid three-phase inverter using PI and PR(seperately control) using SVPWM, this figure aboce is the SVPWM reference signal, which are completely wrong. Somehow the alpha beta component diverge so much from what is intended. what could be the main problem of this? The carrier frequency is 10kHz, and i cant figure out the amplitude because the values kept on diverging and it doesnt show any steadiness
I also tried to switch my own SVPWM design with matlab’s pwm generator and it worked perfectly, I know using the pwm generator is the easier choice, but i want to implement my own SVPWM approach.
This is the DQ component from the PI controller, just before entering into the PWM block, likewise the alpha beta component is also affected by the divergence.
Below is the intended shape of the reference signal for SVPWM, i obtained this from using pure sine waves as the input for the SVPWM, however for an actually inverter, i must use the vref from the PI controller as the input of SVPWMI am simulating for on grid three-phase inverter using PI and PR(seperately control) using SVPWM, this figure aboce is the SVPWM reference signal, which are completely wrong. Somehow the alpha beta component diverge so much from what is intended. what could be the main problem of this? The carrier frequency is 10kHz, and i cant figure out the amplitude because the values kept on diverging and it doesnt show any steadiness
I also tried to switch my own SVPWM design with matlab’s pwm generator and it worked perfectly, I know using the pwm generator is the easier choice, but i want to implement my own SVPWM approach.
This is the DQ component from the PI controller, just before entering into the PWM block, likewise the alpha beta component is also affected by the divergence.
Below is the intended shape of the reference signal for SVPWM, i obtained this from using pure sine waves as the input for the SVPWM, however for an actually inverter, i must use the vref from the PI controller as the input of SVPWM I am simulating for on grid three-phase inverter using PI and PR(seperately control) using SVPWM, this figure aboce is the SVPWM reference signal, which are completely wrong. Somehow the alpha beta component diverge so much from what is intended. what could be the main problem of this? The carrier frequency is 10kHz, and i cant figure out the amplitude because the values kept on diverging and it doesnt show any steadiness
I also tried to switch my own SVPWM design with matlab’s pwm generator and it worked perfectly, I know using the pwm generator is the easier choice, but i want to implement my own SVPWM approach.
This is the DQ component from the PI controller, just before entering into the PWM block, likewise the alpha beta component is also affected by the divergence.
Below is the intended shape of the reference signal for SVPWM, i obtained this from using pure sine waves as the input for the SVPWM, however for an actually inverter, i must use the vref from the PI controller as the input of SVPWM pwm, pulse width modulation, svpwm, inverter, on-grid inverter, simulink, signal, signal processing MATLAB Answers — New Questions
how to extract SIFT features from rgb image in matlab
Hello
I want to extract feature from a color image using SIFT descriptor.
I do not want to convert the image to grayscale and then extract SIFT features.
I want to directly SIFT features extracted from a color image. because color information is important for me.Hello
I want to extract feature from a color image using SIFT descriptor.
I do not want to convert the image to grayscale and then extract SIFT features.
I want to directly SIFT features extracted from a color image. because color information is important for me. Hello
I want to extract feature from a color image using SIFT descriptor.
I do not want to convert the image to grayscale and then extract SIFT features.
I want to directly SIFT features extracted from a color image. because color information is important for me. sift MATLAB Answers — New Questions
How can convert .wav file to .mat file ?
Hello,
I am trying to covert .w to .mat file
and I should to using it in my program
Help me plezzzzzzz :(Hello,
I am trying to covert .w to .mat file
and I should to using it in my program
Help me plezzzzzzz Hello,
I am trying to covert .w to .mat file
and I should to using it in my program
Help me plezzzzzzz how can convert .wav file to .mat file ? MATLAB Answers — New Questions
Which versions of Vivado are supported with which release of HDL Coder?
I would like to use HDL Coder and its HDL Workflow Advisor to automate the programming of my Xilinx (now AMD) FPGA. For this, I need to install Vivado Design Suite as synthesis tool. Could you tell me which versions of Vivado are compatible with which releases of MATLAB/HDL Coder?I would like to use HDL Coder and its HDL Workflow Advisor to automate the programming of my Xilinx (now AMD) FPGA. For this, I need to install Vivado Design Suite as synthesis tool. Could you tell me which versions of Vivado are compatible with which releases of MATLAB/HDL Coder? I would like to use HDL Coder and its HDL Workflow Advisor to automate the programming of my Xilinx (now AMD) FPGA. For this, I need to install Vivado Design Suite as synthesis tool. Could you tell me which versions of Vivado are compatible with which releases of MATLAB/HDL Coder? xilinx, vivado, synthesis, hdl, hdl-coder, xilinx-vivado, amd MATLAB Answers — New Questions
Black horizontal patches in the plot
I am plottting a simple sst difference plot. My lon data is in the range -180 to 180. I have converted it to 0 to 360. After plotting I am geeting these black patches (attached).
clear
clc
% Define the file paths for WeakTEJYears
WeakTEJYears = {
‘F:SST_MA1979.nc’
‘F:SST_MA1983.nc’
‘F:SST_MA1987.nc’
‘F:SST_MA1997.nc’
‘F:SST_MA2002.nc’
‘F:SST_MA2015.nc’
‘F:SST_MA2023.nc’
};
% Define the file paths for StrongTEJYears
StrongTEJYears = {
‘F:SST_MA1985.nc’
‘F:SST_MA1988.nc’
‘F:SST_MA1999.nc’
‘F:SST_MA2009.nc’
‘F:SST_MA2013.nc’
};
% Initialize variables to store the sum of SST data
sst_sum_weak = 0;
sst_sum_strong = 0;
num_weak_files = length(WeakTEJYears);
num_strong_files = length(StrongTEJYears);
lat_min = -25;
lat_max = 70;
lon_min = 0;
lon_max = 360;
for i = 1:num_weak_files
ncfile = WeakTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :); % Re-sort SST data according to longitude sorting
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_weak = sst_sum_weak + mean(sst_region, 3); % Mean over time
end
for i = 1:num_strong_files
ncfile = StrongTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :);
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_strong = sst_sum_strong + mean(sst_region, 3); % Mean over time
end
sst_avg_weak = sst_sum_weak / num_weak_files;
sst_avg_strong = sst_sum_strong / num_strong_files;
sst_diff = sst_avg_strong – sst_avg_weak;
figure;
[lon_mesh, lat_mesh] = meshgrid(longitude(lon_idx), latitude(lat_idx));
contourf(lon_mesh, lat_mesh, sst_diff’, 20, ‘EdgeColor’, ‘none’);
colormap jet;
colorbar;
caxis([-2, 2]);
c.Label.String = ‘Temperature (K)’;
c.Label.FontSize = 18;
c.Label.FontWeight = ‘bold’;
coast = load(‘coastlines’);
coastlon = coast.coastlon;
coastlat = coast.coastlat;
coastlon(coastlon < 0) = coastlon(coastlon < 0) + 360;
hold on;
plot(coastlon, coastlat, ‘k’, ‘LineWidth’, 1.5);
xlim([lon_min, lon_max]);
ylim([lat_min, lat_max]);
title(‘Difference: Strong – Weak TEJ Average SST’, ‘FontSize’, 14);I am plottting a simple sst difference plot. My lon data is in the range -180 to 180. I have converted it to 0 to 360. After plotting I am geeting these black patches (attached).
clear
clc
% Define the file paths for WeakTEJYears
WeakTEJYears = {
‘F:SST_MA1979.nc’
‘F:SST_MA1983.nc’
‘F:SST_MA1987.nc’
‘F:SST_MA1997.nc’
‘F:SST_MA2002.nc’
‘F:SST_MA2015.nc’
‘F:SST_MA2023.nc’
};
% Define the file paths for StrongTEJYears
StrongTEJYears = {
‘F:SST_MA1985.nc’
‘F:SST_MA1988.nc’
‘F:SST_MA1999.nc’
‘F:SST_MA2009.nc’
‘F:SST_MA2013.nc’
};
% Initialize variables to store the sum of SST data
sst_sum_weak = 0;
sst_sum_strong = 0;
num_weak_files = length(WeakTEJYears);
num_strong_files = length(StrongTEJYears);
lat_min = -25;
lat_max = 70;
lon_min = 0;
lon_max = 360;
for i = 1:num_weak_files
ncfile = WeakTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :); % Re-sort SST data according to longitude sorting
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_weak = sst_sum_weak + mean(sst_region, 3); % Mean over time
end
for i = 1:num_strong_files
ncfile = StrongTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :);
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_strong = sst_sum_strong + mean(sst_region, 3); % Mean over time
end
sst_avg_weak = sst_sum_weak / num_weak_files;
sst_avg_strong = sst_sum_strong / num_strong_files;
sst_diff = sst_avg_strong – sst_avg_weak;
figure;
[lon_mesh, lat_mesh] = meshgrid(longitude(lon_idx), latitude(lat_idx));
contourf(lon_mesh, lat_mesh, sst_diff’, 20, ‘EdgeColor’, ‘none’);
colormap jet;
colorbar;
caxis([-2, 2]);
c.Label.String = ‘Temperature (K)’;
c.Label.FontSize = 18;
c.Label.FontWeight = ‘bold’;
coast = load(‘coastlines’);
coastlon = coast.coastlon;
coastlat = coast.coastlat;
coastlon(coastlon < 0) = coastlon(coastlon < 0) + 360;
hold on;
plot(coastlon, coastlat, ‘k’, ‘LineWidth’, 1.5);
xlim([lon_min, lon_max]);
ylim([lat_min, lat_max]);
title(‘Difference: Strong – Weak TEJ Average SST’, ‘FontSize’, 14); I am plottting a simple sst difference plot. My lon data is in the range -180 to 180. I have converted it to 0 to 360. After plotting I am geeting these black patches (attached).
clear
clc
% Define the file paths for WeakTEJYears
WeakTEJYears = {
‘F:SST_MA1979.nc’
‘F:SST_MA1983.nc’
‘F:SST_MA1987.nc’
‘F:SST_MA1997.nc’
‘F:SST_MA2002.nc’
‘F:SST_MA2015.nc’
‘F:SST_MA2023.nc’
};
% Define the file paths for StrongTEJYears
StrongTEJYears = {
‘F:SST_MA1985.nc’
‘F:SST_MA1988.nc’
‘F:SST_MA1999.nc’
‘F:SST_MA2009.nc’
‘F:SST_MA2013.nc’
};
% Initialize variables to store the sum of SST data
sst_sum_weak = 0;
sst_sum_strong = 0;
num_weak_files = length(WeakTEJYears);
num_strong_files = length(StrongTEJYears);
lat_min = -25;
lat_max = 70;
lon_min = 0;
lon_max = 360;
for i = 1:num_weak_files
ncfile = WeakTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :); % Re-sort SST data according to longitude sorting
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_weak = sst_sum_weak + mean(sst_region, 3); % Mean over time
end
for i = 1:num_strong_files
ncfile = StrongTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :);
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_strong = sst_sum_strong + mean(sst_region, 3); % Mean over time
end
sst_avg_weak = sst_sum_weak / num_weak_files;
sst_avg_strong = sst_sum_strong / num_strong_files;
sst_diff = sst_avg_strong – sst_avg_weak;
figure;
[lon_mesh, lat_mesh] = meshgrid(longitude(lon_idx), latitude(lat_idx));
contourf(lon_mesh, lat_mesh, sst_diff’, 20, ‘EdgeColor’, ‘none’);
colormap jet;
colorbar;
caxis([-2, 2]);
c.Label.String = ‘Temperature (K)’;
c.Label.FontSize = 18;
c.Label.FontWeight = ‘bold’;
coast = load(‘coastlines’);
coastlon = coast.coastlon;
coastlat = coast.coastlat;
coastlon(coastlon < 0) = coastlon(coastlon < 0) + 360;
hold on;
plot(coastlon, coastlat, ‘k’, ‘LineWidth’, 1.5);
xlim([lon_min, lon_max]);
ylim([lat_min, lat_max]);
title(‘Difference: Strong – Weak TEJ Average SST’, ‘FontSize’, 14); spatial map, image analysis, matrix manipulation MATLAB Answers — New Questions
How to rotate rectangular with a an angle?
Hey Everone,
I would like to rotate a rectangula with a specific angle.
Any help
Thank youHey Everone,
I would like to rotate a rectangula with a specific angle.
Any help
Thank you Hey Everone,
I would like to rotate a rectangula with a specific angle.
Any help
Thank you rectangular- rotate MATLAB Answers — New Questions
Average Curvature of a Closed 3D Surface
Hi, All —
I would like to compute the average curvature of a closed 3D surface for which I know the inside-outside function, F(x,y,z)=0. (FWIW, centered on the origin and symmetric about all three Cartesian axes.)
I have implemented a couple of different approaches for Gaussian and mean curvature using divergence, the Hessian, the first and second fundamental forms, and other approaches of which I have a similarly weak grasp. I am generally able to get things to work for degenrate cases (e.g., a sphere), but if I increase the complexity of my object, I am tending to get answers that imply I am flirting with the precipice of numerical instability (e.g., imaginary results where Re(x)/Im(x)~10^8).
I like the idea of this approach because it "feels clean": (1) use continuous function; (2) apply magic; (3) integrate in spherical coordinates; and (4) profit. However, I am beginning to think that I need to tune out the sires sweetly singing and go for a more practical (i.e., tractable) approach.
My other idea is to start by using the inside-outside function to generate [X,Y,Z] similar to what is used by surf(). I can then use surfature() from the FEX to get the curvatures at every point on my [X,Y,Z] mesh. Finally, I could convert everything to spherical coordinates and integrate the curvature arrays to get average values.
My concern here is that reregularly-spaced [X,Y,Z] does not translate to regularly-spaced [r,theta,phi], so the calculation is somehow pathologically biased. I am also unsure about how to do the actual integration after converting my array to spherical coordinates.
Apologies for such a long text-dense question. I thought about trying to illustrate this better with a couple of code snippets, but the algebra is really messy and not all that informative.
Thanks, in advance.Hi, All —
I would like to compute the average curvature of a closed 3D surface for which I know the inside-outside function, F(x,y,z)=0. (FWIW, centered on the origin and symmetric about all three Cartesian axes.)
I have implemented a couple of different approaches for Gaussian and mean curvature using divergence, the Hessian, the first and second fundamental forms, and other approaches of which I have a similarly weak grasp. I am generally able to get things to work for degenrate cases (e.g., a sphere), but if I increase the complexity of my object, I am tending to get answers that imply I am flirting with the precipice of numerical instability (e.g., imaginary results where Re(x)/Im(x)~10^8).
I like the idea of this approach because it "feels clean": (1) use continuous function; (2) apply magic; (3) integrate in spherical coordinates; and (4) profit. However, I am beginning to think that I need to tune out the sires sweetly singing and go for a more practical (i.e., tractable) approach.
My other idea is to start by using the inside-outside function to generate [X,Y,Z] similar to what is used by surf(). I can then use surfature() from the FEX to get the curvatures at every point on my [X,Y,Z] mesh. Finally, I could convert everything to spherical coordinates and integrate the curvature arrays to get average values.
My concern here is that reregularly-spaced [X,Y,Z] does not translate to regularly-spaced [r,theta,phi], so the calculation is somehow pathologically biased. I am also unsure about how to do the actual integration after converting my array to spherical coordinates.
Apologies for such a long text-dense question. I thought about trying to illustrate this better with a couple of code snippets, but the algebra is really messy and not all that informative.
Thanks, in advance. Hi, All —
I would like to compute the average curvature of a closed 3D surface for which I know the inside-outside function, F(x,y,z)=0. (FWIW, centered on the origin and symmetric about all three Cartesian axes.)
I have implemented a couple of different approaches for Gaussian and mean curvature using divergence, the Hessian, the first and second fundamental forms, and other approaches of which I have a similarly weak grasp. I am generally able to get things to work for degenrate cases (e.g., a sphere), but if I increase the complexity of my object, I am tending to get answers that imply I am flirting with the precipice of numerical instability (e.g., imaginary results where Re(x)/Im(x)~10^8).
I like the idea of this approach because it "feels clean": (1) use continuous function; (2) apply magic; (3) integrate in spherical coordinates; and (4) profit. However, I am beginning to think that I need to tune out the sires sweetly singing and go for a more practical (i.e., tractable) approach.
My other idea is to start by using the inside-outside function to generate [X,Y,Z] similar to what is used by surf(). I can then use surfature() from the FEX to get the curvatures at every point on my [X,Y,Z] mesh. Finally, I could convert everything to spherical coordinates and integrate the curvature arrays to get average values.
My concern here is that reregularly-spaced [X,Y,Z] does not translate to regularly-spaced [r,theta,phi], so the calculation is somehow pathologically biased. I am also unsure about how to do the actual integration after converting my array to spherical coordinates.
Apologies for such a long text-dense question. I thought about trying to illustrate this better with a couple of code snippets, but the algebra is really messy and not all that informative.
Thanks, in advance. differential geometry, curvature, spherical averaging MATLAB Answers — New Questions