Can I match data from several find functions?

조회 수: 1 (최근 30일)
Diana Mikhail
Diana Mikhail 2017년 4월 27일
댓글: Diana Mikhail 2017년 4월 28일
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)

채택된 답변

Joseph Cheng
Joseph Cheng 2017년 4월 28일
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)
  댓글 수: 1
Diana Mikhail
Diana Mikhail 2017년 4월 28일
Thank you very much! This works great. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Condensed Matter & Materials Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by