how to search a specific element/text from excel and then show if it is true/false

1 view (last 30 days)
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

Answers (1)

Mathieu NOE
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
Aiman Zara
Aiman Zara on 5 Apr 2023
@Peter Perkins thanks for the response, actually that's a good one(My tomatoes sometimes get Fusarium wilt. It's really annoying). Now can you please help me code this?
Peter Perkins
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 = 5×3 table
CottonStage DiseaseSeverity Disease ___________ _______________ _____________________ "Stage1" "harmful" "Fusarium wilt" "Stage2" "harmful" "Alternaria leafspot" "Stage3" "Critical" "Fusarium wilt" "Stage4" "Medium" "Fungal" "Stage5" "Medium" "Worm"
T = convertvars(T,1:3,"categorical")
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
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",:)
ans = 2×3 table
CottonStage DiseaseSeverity Disease ___________ _______________ _____________ Stage1 harmful Fusarium wilt Stage3 Critical Fusarium wilt
or maybe
any(T.Disease == "Fusarium wilt")
ans = logical
1
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 = 5×3 table
CottonStage DiseaseSeverity Disease ___________ _______________ ___________________ Stage1 harmful Fusarium wilt Stage2 harmful Alternaria leafspot Stage3 Critical Fusarium wilt Stage4 Medium Fungal Stage5 Medium Worm
T(T.DiseaseSeverity< "Critical",:)
ans = 4×3 table
CottonStage DiseaseSeverity Disease ___________ _______________ ___________________ Stage1 harmful Fusarium wilt Stage2 harmful Alternaria leafspot Stage4 Medium Fungal Stage5 Medium Worm

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!