how to search a specific element/text from excel and then show if it is true/false
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Mathieu NOE
on 5 Apr 2023
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 Comments
Peter Perkins
on 6 Apr 2023
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",:)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!