Borrar filtros
Borrar filtros

error in applying the condition to the if loop

1 visualización (últimos 30 días)
Alberto Acri
Alberto Acri el 17 de Jul. de 2023
Respondida: Diya Tulshan el 17 de Jul. de 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 comentario
Diwakar Diwakar
Diwakar Diwakar el 17 de Jul. de 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');

Iniciar sesión para comentar.

Respuesta aceptada

Diya Tulshan
Diya Tulshan el 17 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by