The character vector Materials is a single column, 40 row vector with the names of the necessary materials.
The numeric vector Inventory is a single column, 40 row vector with the amount of each material in stock.
The numeric vector Needed is a single column, 40 row vector with the amount of each material we require.
The numeric vector Defecit is a single column, 40 row vector with the amount of each material we lack.
In order to parse down the final product to show just the rows of materials that we need to order, I wrote the following bit of code
DF = all (Deficit > 0 , length(Deficit)) %DF is a column vector the same length as Deficit that has a 1 if we need to order, a 0 if we do not.
DefecitFinal = Defecit(DF,:) %Similar code for the other numeric vectors to provide just the rows that we need to order
MaterialsFinal = Materials(DF,:) %Provides an error message
I feel like theres a really simple way that i'm just not familiar with to adjust the Materials data as well.

댓글 수: 2

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 20일
Please explain the question in simple maths way, not as per your subjects.
What you have?
What result you are expecting?
Justin Alexander
Justin Alexander 2019년 6월 20일
There’s a column of materials.
There’s a column of 0’s and 1’s.
I need only the materials next to 1’s.

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

 채택된 답변

Matt J
Matt J 2019년 6월 20일
편집: Matt J 2019년 6월 20일

0 개 추천

Works fine for me,
Materials=["Iron";"Steel";"Wood";"Cheese"];
DF=logical([1 0 0 1].');
>> MaterialsFinal = Materials(DF)
MaterialsFinal =
2×1 string array
"Iron"
"Cheese"

댓글 수: 1

Justin Alexander
Justin Alexander 2019년 6월 20일
편집: Justin Alexander 2019년 6월 20일
I’ll give it another go then trying that once I get back. Thanks for the heads up.
UPDATE:
So i don't have DF as a logic array which is causing the problem. I'll try getting it as one brb.
SOLVED:
Yup, inserting the line
DF=logial(DF) ;
sovled the issue! Thanks!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

태그

질문:

2019년 6월 20일

편집:

2019년 6월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by