Can I match data from several find functions?

1 view (last 30 days)
I am working on a Matlab class project. In this project I made a data file with 20 materials and 5 of their material properties and wanted to allow a user to enter values needed for the 5 properties and have the program tell them what material qualifies. I decided to use 5 find functions to find out which rows (each row is a different material) qualify for each property but I am unsure how to make it find the rows that surpass all the properties since the resulting vectors from the find functions are different sizes.
% Have user enter properties
Mod=input('Enter the minimum Young''s Modulus: ');
TS=input('Enter the minimum Tensile Strength: ');
YS=input('Enter the minimum Yield Strength: ');
Den=input('Enter the maximum Density: ');
HC=input('Enter the minimum Heat Capacity: ');
% Run find statement
ModMat=find(Modulus>=Mod);
TSMat=find(TensileStrength>=TS);
YSMat=find(YieldStrength>=YS);
DenMat=find(Density<=Den);
HCMat=find(HeatCapacity>=HC);
% Show resulting row in material form
Material=find(ModMat==TSMat==YSMat==DenMat==HCMat)

Accepted Answer

Joseph Cheng
Joseph Cheng on 28 Apr 2017
what you should do is get rid of the find() for each parameter filter. keep it as a logical and then you can directly use the logical operator & to compare them. i've quickly adjusted your code to use some dummy data but you can step through it and i'd take a look at the second half of the code to see that by removing the find() you get an array of 1's where it meets your condition and 0's when it doesn't. then the last line compares each one and only reports out when all 5 have a 1 in them. (otherwise you could also sum the values in rows and find when it you equal 5;
%to make it simple example material names is the column number
properties = randi(10,20,5) %generate some dummy numbers)
%so lets say we want to find the row/material with
Modu=5;
TS=5;
YS=5;
Den=5;
HC=5;
ModMat=properties(:,1)>=Modu;
TSMat=properties(:,2)>=TS;
YSMat=properties(:,3)>=YS;
DenMat=properties(:,4)<=Den;
HCMat=properties(:,5)>=HC;
Material=find(ModMat & TSMat & YSMat & DenMat &HCMat)

More Answers (0)

Categories

Find more on Condensed Matter & Materials Physics 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!