I'm trying to make a matrix of user chosen values and a user chosen size.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
KSSV
am 28 Sep. 2017
I think you are making code complicated.....you may staright away ask for dimensions....and then proceed.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!