フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Indexing Values from a structure array

1 回表示 (過去 30 日間)
Tyrell Warrick
Tyrell Warrick 2019 年 3 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件のコメント
darova
darova 2019 年 3 月 6 日
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

回答 (1 件)

Agnish Dutta
Agnish Dutta 2019 年 3 月 18 日
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:

この質問は閉じられています。

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by