Filter löschen
Filter löschen

error in applying the condition to the if loop

1 Ansicht (letzte 30 Tage)
Alberto Acri
Alberto Acri am 17 Jul. 2023
Beantwortet: Diya Tulshan am 17 Jul. 2023
Hi. I need to change all lines with 101 and [100;101] in 'test_2' with '[]' in both 'test_2' and 'test_1'.
I succeeded with 101, but can't get the same result with [100;101].
'test_1_out' and 'test_2_out' are the results I need to obtain.
test_1 = importdata("test_1.mat");
test_2 = importdata("test_2.mat");
for K = 1:length(test_1)
if test_2{K,1} == 101
test_1{K,1} = [];
test_2{K,1} = [];
end
if test_2{K,1} == [100;101] % error
test_1{K,1} = [];
test_2{K,1} = [];
end
end
  1 Kommentar
Diwakar Diwakar
Diwakar Diwakar am 17 Jul. 2023
test_1 = importdata("test_1.mat");
test_2 = importdata("test_2.mat");
for K = 1:length(test_1)
if test_2(K, 1) == 101 || isequal(test_2(K, 1), [100;101])
test_1(K, 1) = [];
test_2(K, 1) = [];
end
end
save('test_1_out.mat', 'test_1');
save('test_2_out.mat', 'test_2');

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Diya Tulshan
Diya Tulshan am 17 Jul. 2023
Hii Alberto Arci,
I understand you want to debug the code and get the desired output.
Solution given below might be one of the possible workflow:-
test_1 = importdata("test_1.mat");
test_2 = importdata("test_2.mat");
for K = 1:length(test_1)
if isequal(test_2{K,1}, 101) || isequal(test_2{K,1}, [100;101])
test_1{K,1} = [];
test_2{K,1} = [];
end
end

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by