I am trying to write a while loop. I want to read a matrix first, once ive done this i want to ask the user for co-ordinates, if those co-ordinates lie outside the matrix i want to display "these co-ordinates dont lie within the mining area" since the matrix displays a mine.
Once a suitable set of co-ordinates within the matrix is established i then want to ensure that the value in the matrix selected is zero, should the value not be zero i want to ask the user for a new set of co-ordinates.
Here's what i have so far,i feel like i lmost have it worked out however i just cant get the last part to work.
dirt_grid = csvread('dirtgrid.csv');for base_station_x = input('Enter an x co-ordinate for the base station: ' ); if base_station_x > length (dirt_grid) disp('The x co-ordinate is outside the mining area, please enter another co-ordinate') base_station_x = input('Enter an x co-ordinate for the base station: ' ); endendfor base_station_y = input('Enter an y co-ordinate for the base station: ' ); while base_station_y > length (dirt_grid) disp('The y co-ordinate outside mining area, please enter another co-ordinate') base_station_y = input('Enter an y co-ordinate for the base station: ' ); endendbase_station = dirt_grid (base_station_x, base_station_y); while base_station >= 1 disp('The location you have entered is not a valid location') end
I am aware that this program forms a infinite loop but im not sure where i should place this last loop to make the problem work. Thanks for any assistance anyone is able to provide…
Best Answer