I'm trying to make a matrix of user chosen values and a user chosen size.

2 visualizaciones (últimos 30 días)
I am trying to create a code that asks the user for input about a matrix that they want to create. I am asking the user for the starting row value, ending row value, starting column value and ending column value. I am thinking that with that data a matrix of [NxN] size can be created but I just keep getting a single row and changing columns. I also added if loops to prevent a negative value from being used.
if true
b = 1;
while b == 1
userVecRowMin = input('Please input starting row index >> ');
if userVecRowMin <= 0
disp('Did you mean to input another value? Please input another value.');
else
b = 2;
end
end
while b == 2
userVecColMin = input('Please input starting column index >> ');
if userVecColMin <= 0
disp('Did you mean to input another value? Please input another value.');
else
b = 3;
end
end
while b == 3
userVecRowMax = input('Please input ending row index >> ');
if userVecRowMax <= 0
disp('Did you mean to input another value? Please input another value.');
else
b = 4;
end
end
while b == 4
userVecColMax = input('Please input ending column index >> ');
if userVecColMax <= 0
disp('Did you mean to input another value? Please input another value.');
else
b = 5;
end
end
a = 1;
while(a == 1)
userIncrem = input('Please input desired incrementation >> ');
if userIncrem <= 0
disp('Did you mean to input another value? Please input another value.');
else
a = 2;
end
userVec = [userVecRowMin:userVecRowMax,userVecColMin:userVecColMax];
disp(userVec);
end
end
  2 comentarios
KSSV
KSSV el 28 de Sept. de 2017
I think you are making code complicated.....you may staright away ask for dimensions....and then proceed.
Stephen23
Stephen23 el 28 de Sept. de 2017
@Rasean Hyligar: this is a waste of time. Simpler would be to use:
  • a function with a user-defined input.
  • a text file and read it into memory.
  • a uitable
You will spend hours on this, when a uitable will do it straight away.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Logical 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!

Translated by