Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Indexing Values from a structure array

1 visualización (últimos 30 días)
Tyrell Warrick
Tyrell Warrick el 6 de Mzo. de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Positive_Torque_Values = double.empty;
Speed_Values = double.empty;
index = 1;
index2 = 1;
for i = HL_simout.Motor_Torque.Data(index)
if HL_simout.Motor_Torque.Data(index) >= 0
Positive_Torque_Values(index)= HL_simout.Motor_Torque.Data(index) ;
Speed_Values(index2)= HL_simout.Motor_Speed.Data(index);
index2 = index2 + 1;
end
index = index + 1;
end
a = size(Speed_Values);
b = size(Positive_Torque_Values);
disp(a)
disp(b)
title('Motor Torque Vs Motor Speed')
scatter(Speed_Values,Positive_Torque_Values)
xlabel('Motor Speed [RPM]')
ylabel('Motor Torque [Nm]')
I'm trying to take values from a column of data stored in a structure created by MATLAB simulink and take all the values grearer than zero(0) and store it in a seprate array. However, im only getting one value in the new array hence its not going through the entire structure list
  1 comentario
darova
darova el 6 de Mzo. de 2019
index2 = 1;
n = length(HL_simout.MOtor_Torque.Data); % number of rows
for i = 1:n
if HL_simout.Motor_Torque.Data(i) >= 0
Positive_Torque_Values(index2)= HL_simout.Motor_Torque.Data(i) ;
Speed_Values(index2)= HL_simout.Motor_Speed.Data(i);
index2 = index2 + 1;
end
end

Respuestas (1)

Agnish Dutta
Agnish Dutta el 18 de Mzo. de 2019
You can use logical indexing to obatin the non zero values from the structure arrays as per the code below:
Positive_Torque_Values = HL_simout.Motor_Torque.Data(HL_simout.Motor_Torque.Data > 0);
Speed_Values = HL_simout.Motor_Speed.Data(HL_simout.Motor_Torque.Data > 0);
From the code that you've provided, I'm assuming that you want the values of Speed and Torque at all those points where the Torque is greater than zero.
Refer to the logical indexing section of the following document for more information:

La pregunta está cerrada.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by