Creating a matrix from user input

조회 수: 6 (최근 30일)
Lucy Doyle
Lucy Doyle 2018년 4월 4일
댓글: Bob Thompson 2018년 4월 4일
I am a first year engineering student trying to answer a question similar to this:
  • specify the number of shelves in a cupboard
  • specify the number of spaces on each shelf
  • for each space, specify its dimensions (width, height and depth)
  • for each space, specify its use (food, plates or cutlery)
  • for each space, specify the x and y coordinate on its given shelf.
  댓글 수: 4
David Fletcher
David Fletcher 2018년 4월 4일
편집: David Fletcher 2018년 4월 4일
They're not unknown as such, I imagine you design a script that will input those criteria (any arbitrary input will do) and save them in a suitable structure (I don't think it will be a matrix though)
Bob Thompson
Bob Thompson 2018년 4월 4일
I'm a little confused about the context of these questions, so I can't give a particularly specific answer. If you're just looking to have the user input the values themselves then you can use the input() command, and store the information as David mentioned. Because the data all seems to be about a specific object I would suggest using a structure variable type.
numshelf = input('specify the number of shelves in a cupboard: ');
shelf = struct('numshel',numshelf);
[shelf.numspace] = input('specify the number of spaces on each shelf: ');
You can go multiple layers deep if you would like (shelf.space(1).dim) and possibly couple that with a for loop to add dimensions for different characteristics, or you could also just do a matrix with values (shelf.dim = matrix of size numberofspaces X numberofdimensions). Plenty of options to choose from.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Aerospace Applications에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by