I am trying to work out a volume given input values but it says theres an error ''Index must not exceed 1''?
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to work out volume of building using number of floors, width of floors, length of floors and height of floors but when it comes to working it out an error comes up about index exceeding number of array elements and says ins=dex must not exceed 1. Im not sure how to fix this.
n=1;
Building = input('Enter Building name: ','s');
while isempty(Building)
Building = input('Enter Building name: ','s');
end
sBuilding(n).bName =Building;
sBuilding(n).bNoOfFloors = input('Enter Number of Floors as an integer: ');
NumberOfFloors = sBuilding(n).bNoOfFloors;
sBuilding(n).bWidth = input('Enter the floors width as an integer: ');
WidthOfFloors = sBuilding(n).bWidth;
sBuilding(n).bLength = input('Enter the floors length as an integer: ');
LengthOfFloors = sBuilding(n).bLength;
sBuilding(n).bHeight = input('Enter the floors height as an integer: ');
HeightOfFloors = sBuilding(n).bHeight;
BuildingVolume= NumberOfFloors(WidthOfFloors*LengthOfFloors*HeightOfFloors);
disp('Building volume is:'+BuildingVolume)
disp("")
댓글 수: 0
채택된 답변
the cyclist
2022년 5월 3일
This expression:
NumberOfFloors(WidthOfFloors*LengthOfFloors*HeightOfFloors)
is trying to index into the variable NumberOfFloors.
Did you perhaps mean
NumberOfFloors*WidthOfFloors*LengthOfFloors*HeightOfFloors?
Also, you cannot concatenate character array and numbers with this syntax:
disp('Building volume is:'+BuildingVolume)
You can use a string instead:
disp("Building volume is:"+BuildingVolume)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!