change row when compiling an array

2 次查看(过去 30 天)
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