Hi guysy,
I have different cases I want to calculate and plot. I am wondering if there is anyway to use input function to prompt user to choose the cases through typing the cases numbers to array with flexible length for example Cases=inpute [ 1 3 5] or Cases=inpute [ 1 3 5 9]
I appreciate your help thanks

 채택된 답변

Walter Roberson
Walter Roberson 2014년 1월 4일

2 개 추천

Cases = input('Enter cases with [ ] around them');
and user would have to type in
[1 3 5 9]
including the []
Alternately,
Cases_str = input('Enter cases separated by spaces or commas' 's');
Cases = num2str(Cases_str);

댓글 수: 3

Abdulaziz
Abdulaziz 2014년 1월 5일
thank you Walter your suggestions always helpful
tbaracu
tbaracu 2021년 1월 18일
For vectors is simple. But for mxn matrix how it can be done? Give an example pls.
Walter Roberson
Walter Roberson 2021년 1월 18일
data = input('Enter 2D array with [] around it and commas between the columns and semicolon at end of each row ')
Enter 2D array with [] around it and commas between the columns and semicolon at end of each row
[3, 4, 5; -1, -2, -3]
data =
3 4 5
-1 -2 -3

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Dr. Kelsey Joy
Dr. Kelsey Joy 2021년 11월 27일

0 개 추천

Also you can consider using the listdlg() function, if you want another way to collect this data with set values and are okay with dialog boxes.
Another thing you could consider is having the user input numbers one at a time in a for loop (see example: https://www.mathworks.com/matlabcentral/fileexchange/102644-educational-building-arrays-with-for-loops-d-d?s_tid=prof_contriblnk).

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2014년 1월 4일

답변:

2021년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by