I am trying to work out a volume given input values but it says theres an error ''Index must not exceed 1''?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jamie Hogan
el 3 de Mayo de 2022
Respondida: the cyclist
el 3 de Mayo de 2022
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 comentarios
Respuesta aceptada
the cyclist
el 3 de Mayo de 2022
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!