change row when compiling an array
Show older comments
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 Comment
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
Accepted Answer
More Answers (1)
Walter Roberson
on 10 Jun 2022
0 votes
Store into answer{i}
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!