필터 지우기
필터 지우기

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