Creating a matrix for specific variables

1 次查看(过去 30 天)
t=0:0.0000001:0.0001;
DABi=zeros(1,length(t));
y=zeros(1,length(t));
vin=zeros(1,length(t));
vo=zeros(1,length(t));
L=27e-6;
f=50e3;
vo=square(2*pi*f*t);
for i=1:length(y)
j=mod(i-30,length(y))+1;
vin(i)=vo(j);
end
vin=800.*vin;
vo=400.*vo;
for i=2:length(t)
DABi(i)= ((vin(i)-vo(i))/L)*(t(i)-t(i-1))+DABi(i-1);
end
DABi=DABi-mean(DABi);
plot(t,DABi,"m");
hold on;
plot(t,vinp,"b");
hold on;
plot(t,vout,"r");
grid on;
legend('Current','Input Voltage', 'OUtput Voltage')
xlim([0 0.0001])
hold off;
I want to create 2 different matrices first based on the Input voltage and current and the second based on Output voltage and current. Let discuss only input voltage and current case.
For the first matrix I want to focus only on the point when input voltage switches (just the switching instance) to 400 and -400 value (All the rest point should be excluded from the matrix). When voltage switches to 400 value I want to look at current if it is negative I should get 1 if it is zero I should get 0 if it is positive value I should get +1. Whereas for -400 value if current is positive I should get 1 if it is zero I should get 0 if it is negative value I should get -1

采纳的回答

surya venu
surya venu 2024-6-11
Hi,
To create the matrix based on the Input voltage and current focusing only on the points where the input voltage switches to 400 or -400, and associating the current values accordingly, we can follow these steps:
  1. Identify the switching points: We need to find the indices where vin switches to 400 or -400. This can be done by looking for the differences between consecutive elements and finding where these changes occur.
  2. Classify the current at these points: Based on the value of the current (DABi) at these switching points, classify according to the rules you provided.
Here is the MATLAB code
t = 0:0.0000001:0.0001;
DABi = zeros(1,length(t));
vin = zeros(1,length(t));
vo = zeros(1,length(t));
L = 27e-6;
f = 50e3;
vo = square(2*pi*f*t);
for i = 1:length(vo)
j = mod(i-30,length(vo)) + 1;
vin(i) = vo(j);
end
vin = 800.*vin;
vo = 400.*vo;
for i = 2:length(t)
DABi(i) = ((vin(i) - vo(i)) / L) * (t(i) - t(i-1)) + DABi(i-1);
end
DABi = DABi - mean(DABi);
% Finding the switching points
switchingIndices = find(diff(vin) ~= 0) + 1;
inputSwitchMatrix = zeros(length(switchingIndices), 2);
for i = 1:length(switchingIndices)
idx = switchingIndices(i);
inputVoltage = vin(idx);
currentAtSwitch = DABi(idx);
% Determine the matrix value based on your conditions
if inputVoltage == 400
% For 400V switch
if currentAtSwitch > 0
inputSwitchMatrix(i, :) = [400, 1];
elseif currentAtSwitch == 0
inputSwitchMatrix(i, :) = [400, 0];
else\
inputSwitchMatrix(i, :) = [400, -1];
end
elseif inputVoltage == -800
% For -400V switch, note your vin is actually 800 or -800
if currentAtSwitch > 0
inputSwitchMatrix(i, :) = [-800, 1];
elseif currentAtSwitch == 0
inputSwitchMatrix(i, :) = [-800, 0];
else
inputSwitchMatrix(i, :) = [-800, -1];
end
end
end
Hope it helps.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Power Converters 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by