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!