error in applying the condition to the if loop

1 次查看(过去 30 天)
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 个评论
Diwakar Diwakar
Diwakar Diwakar 2023-7-17
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');

请先登录,再进行评论。

采纳的回答

Diya Tulshan
Diya Tulshan 2023-7-17
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by