avoid for loop in a specific code
1 回表示 (過去 30 日間)
古いコメントを表示
Could anyone help me if there is any way to avoid for loop in the following code: Both Target and predicted_target are vectors with n rows and one column.
new_classes=cell(size(Target,1),1);
for i=1:size(Target,1)
if (strcmp(predicted_target(i),Target{i}))
new_classes{i}=strcat('c',Target{i});
else
new_classes{i}=strcat('E',Target{i});
end
end
3 件のコメント
Bruno Luong
2019 年 8 月 10 日
編集済み: Bruno Luong
2019 年 8 月 10 日
@MA: You change cell array to char array, you change variable name predicted_target to predicted_t.
Please don't do that if you want getting exactly the code that works
採用された回答
Bruno Luong
2019 年 8 月 10 日
編集済み: Bruno Luong
2019 年 8 月 10 日
predicted_target = {'1'; '0'; '0'; '1'};
Target = {'0'; '1'; '1'; '1'};
prefix = {'E'; 'c'}
new_classes = strcat(prefix(strcmp(predicted_target,Target)+1),Target)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!