필터 지우기
필터 지우기

change row when compiling an array

조회 수: 4 (최근 30일)
Pas182
Pas182 2022년 6월 10일
댓글: Pas182 2022년 6월 14일
Hi everyone!
with a for loop i'm compiling an array based on the answer that i get from the script.
count(i)=0;
for i=1:length(Lamp_config)
st1(i)=(strcmp(Lamp_config(i),h));
st2(i)=(strcmp(Lamp_config(i),o));
st3(i)=(strcmp(Lamp_config(i),l));
st4(i)=(strcmp(Lamp_config(i),m));
if st2(i)==1
o1=ismember(0,NaDFIR_from_tool(i,:));
o2=ismember(39,NaDFIR_from_tool(i,:));
o3=ismember(175,NaDFIR_from_tool(i,:));
o4=ismember(174,NaDFIR_from_tool(i,:));
o5=ismember(172,NaDFIR_from_tool(i,:));
o6=ismember(168,NaDFIR_from_tool(i,:));
o7=ismember(40,NaDFIR_from_tool(i,:));
if o1 == 1
count(i)=count(i)+1;
answer{count(i)} ='DTC_enabled'
else
count(i)=count(i)+1;
answer{count(i)} ='DTC_not_enabled'
end
if o2 == 1
count(i)=count(i)+1;
answer{count(i)} ='1_trip_failed'
else
count(i)=count(i)+1;
answer{count(i)} ='1_trip_NOT_failed'
end
if o3 == 1
count(i)=count(i)+1;
answer{count(i)} ='2 trip failed'
else
count(i)=count(i)+1;
answer{count(i)} ='2 trip NOT failed'
end
if o4 == 1
count(i)=count(i)+1;
answer{count(i)} ='3 trip failed'
else
count(i)=count(i)+1;
answer{count(i)} ='3 trip NOT failed'
end
if o5 == 1
count(i)=count(i)+1;
answer{count(i)} ='fault passing'
else
count(i)=count(i)+1;
answer{count(i)} ='fault NOT passing'
end
if o6 == 1
count(i)=count(i)+1;
answer{count(i)} ='1 trip healing'
else
count(i)=count(i)+1;
answer{count(i)} ='1 trip NOT healing'
end
if o7 == 1
count(i)=count(i)+1;
answer{count(i)} ='2 trip healing'
else
count(i)=count(i)+1;
answer{count(i)} ='2 trip NOT healing'
end
end
The issue is that at the next i, the answer array will be overwritten. My target is that at the next i the array begins to be compilated in the second row.
So how can i switch row array when the i changes?
thank you so much!
  댓글 수: 1
Jan
Jan 2022년 6월 10일
편집: Jan 2022년 6월 10일
What does "compilated in the 2nd row" mean? Do you mean concatenated?
Hints:
  • strcmp replies a logical already. There is no need to compare it with 1:
st1(i) = strcmp(Lamp_config(i), h);
if st2(i) % without == 1
o1 = ismember(0, NaDFIR_from_tool(i,:));
% Faster: o1 = any(NaDFIR_from_tool(i,:) == 0)
if o1 % without == 1
...
end
end

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2022년 6월 10일
Pool = {'DTC_enabled', 'DTC_not_enabled'; ...
'1_trip_failed', '1_trip_NOT_failed'; ...
'2 trip failed', '2 trip NOT failed'; ...
'3 trip failed', '3 trip NOT failed'; ...
'fault passing', 'fault NOT passing'; ...
'1 trip healing', '1 trip NOT healing'; ...
'2 trip healing', '2 trip NOT healing'};
asnwer = {};
for i = 1:length(Lamp_config)
st1(i) = strcmp(Lamp_config(i), h);
if st2(i)
match = ismember([0; 39; 175; 174; 172; 168; 40], NaDFIR_from_tool(i,:));
answer = [answer, Pool(:, match + 1)];
end
end
I'm not sure, if this matchs your needs, because I do not understand the term "compile" here. But maybe this simplified versions is much easier to adjust to your needs.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 6월 10일
Store into answer{i}

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by