Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Function Requests and receives from the user the dimensions of the sampled matrix until a proper value is obtained

1 回表示 (過去 30 日間)
Netanel malihi
Netanel malihi 2020 年 6 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
hello,
im working on a project in matlab for course i am doing in college .
i want to build a function that Requests and receives from the user the dimensions of the sampled matrix until a proper value is obtained (Two inputs) (the dimensions should be between 4 and 10 lines) inclusive (and between 12 and 7 columns (Including). The input needs to note what is the permissible range for input values. Proper by this setting, issue a message explaining exactly what the problem is and request a new input.
I might be far for the correct code but that's cause i am new at this
thank you for any help !!

回答 (3 件)

madhan ravi
madhan ravi 2020 年 6 月 4 日
  • infinite loop
  • if true , break
  • else input again and break
Note: (m condition goes here) && (n condition goes here), You have m and n swapped rectify it.

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020 年 6 月 4 日
function [R, C]=MD(m,n)
while m<4 || m>10 || n>12 || n<7
disp('Wrong dimensions are entered: Enter new dimensions! m = [4, 10], n=[7, 12]')
m= input('Enter the number of rows: ');
n = input('Enter the number of colmuns: ');
end
disp('Well Done!')
R = m;
C = n;
fprintf('You have entered: %.0f Rows and %.0f Columns \n', R, C)
end
  1 件のコメント
Netanel malihi
Netanel malihi 2020 年 6 月 4 日
Thank you amigo!!! But its not working[ Not enough input arguments.
Error in MatrixDimInput (line 2)
while m<4 || m>10 || n>12 || n<7

David Hill
David Hill 2020 年 6 月 4 日
I would put your input into a continuous while loop and break the loop when the condition is met.
function [m,n]=MatrixDimInput()
while 1
m=input('Enter the number of rows of the matrix: ');
n=input('Enter the number of columns of the matrix: ');
if m<13&&m>7&&n<10&&n>4
break;
end
disp('wrong dimensions try again');
end
end
  2 件のコメント
Netanel malihi
Netanel malihi 2020 年 6 月 4 日
Thank you very much!! it works
Can you explain what the 1 after the while stands for?
David Hill
David Hill 2020 年 6 月 4 日
1==true, therefore loop continues indefinately until broken.

この質問は閉じられています。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by