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
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Testing Frameworks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!