Filter löschen
Filter löschen

change row when compiling an array

4 Ansichten (letzte 30 Tage)
Pas182
Pas182 am 10 Jun. 2022
Kommentiert: Pas182 am 14 Jun. 2022
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 Kommentar
Jan
Jan am 10 Jun. 2022
Bearbeitet: Jan am 10 Jun. 2022
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 10 Jun. 2022
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.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 10 Jun. 2022
Store into answer{i}

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by