How to replace string using if else condition In MATLAB

3 ビュー (過去 30 日間)
Stephen john
Stephen john 2022 年 8 月 26 日
コメント済み: KSSV 2022 年 8 月 26 日
Hello Everyone I Hope you are doing well.
I have structure Attached below TrainedModelPrediction.mat . which has the String name as Prediction Which has the class name 'Apple'
I have the 4 classes Apple, Orange, Mango Bannna.
I want to replace the string (Prediction) in Structure with Apple and Non-Apple. For example if 'Orange' string(Prediction) comes in structure. It should be replaced By 'Non-Apple', similarly for the remaining 2 strings Mango and Bannana.
If 'Apple' string(Prediction) comes in structure it remains the same.
I was trying the Following code, But i think it is wrong. Can anybody Help me with this
if strcmp(ModelPrediction.Prediction,'Apple')
content_str = 'Apple';
elseif (ModelPrediction.Prediction,'Orange')
content_str = 'Non-Apple';
end

回答 (1 件)

KSSV
KSSV 2022 年 8 月 26 日
if strcmp(ModelPrediction.Prediction,'Apple')
content_str = 'Apple';
else
content_str = 'Non-Apple';
end
  2 件のコメント
Stephen john
Stephen john 2022 年 8 月 26 日
@KSSV I have multiple Prediction. Then How can i apply this on that?
KSSV
KSSV 2022 年 8 月 26 日
You have shown us only one structure in the mat file attached. How are the other structures?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by