how to search a specific element/text from excel and then show if it is true/false
1 回表示 (過去 30 日間)
古いコメントを表示
From excel i want to search a disease named "Fusarium wilt" and then I want to show that this disease is true(available in the excel). how to do that? please share some sample code for doing this, i couldnot find any and struggling to find help as I am not good in coding
0 件のコメント
回答 (1 件)
Mathieu NOE
2023 年 4 月 5 日
hello
simply do that
the answer is logical 1 (true) as soon as contains at least one 1 (logical) , i.e. one instance of Fusarium appears in the table
answer =
logical
1
T = readtable('Book1Excel.csv')
% T =
%
% 5×3 table
%
% CottonStage DiseaseSeverity Disease
% ___________ _______________ _______________________
%
% {'Stage1'} {'harmful' } {'Fusarium wilt' }
% {'Stage2'} {'harmful' } {'Alternaria leafspot'}
% {'Stage3'} {'Critical'} {'Fusarium wilt' }
% {'Stage4'} {'Medium' } {'Fungal' }
% {'Stage5'} {'Medium' } {'worm' }
idx = contains(T.Disease,'Fusarium');
answer = any(idx)
3 件のコメント
Peter Perkins
2023 年 4 月 6 日
I can't really help you write your code because I'm not sure what you need to do. All I was suggesting is that if that 5x3 table represents something like an Nx3, with large N, then this
CottonStage = ["Stage1";"Stage2";"Stage3";"Stage4";"Stage5"];
DiseaseSeverity = ["harmful";"harmful";"Critical";"Medium";"Medium"];
Disease = ["Fusarium wilt";"Alternaria leafspot";"Fusarium wilt";"Fungal";"Worm"];
T = table(CottonStage,DiseaseSeverity,Disease)
T = convertvars(T,1:3,"categorical")
might be more useful than a large table full of raw text. For example, To find rows with Fusarium, it doesn't have a huge benefit over raw text
T(T.Disease == "Fusarium wilt",:)
or maybe
any(T.Disease == "Fusarium wilt")
but for example, you might make DiseaseSeverity ordinal, and select data below some value.
T.DiseaseSeverity = categorical(T.DiseaseSeverity,["Medium";"harmful";"Critical"],Ordinal=true)
T(T.DiseaseSeverity< "Critical",:)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!