How to get user inputs into a single vector

조회 수: 7 (최근 30일)
Jessica Parry
Jessica Parry 2013년 4월 7일
for orders = [0:1:y]
disp(' ')
str3 = 'The coefficient of x^';
str4 = ' is ';
alltogether = [str3 num2str(orders) str4];
input(alltogether);
end
Part of the code im writing performs the above task, where y is variable depending previously what a user inputs. After the user has completed this section i would like all the numbers to be collated into a single vector form, like so;
The polynomial of interest has order 3.
The coefficient of x^0 is 1
The coefficient of x^1 is 2
The coefficient of x^2 is 3
The coefficient of x^3 is 4
P = [1 2 3 4]
Please and thanks

채택된 답변

Walter Roberson
Walter Roberson 2013년 4월 7일
Before the loop:
count = 0;
In the loop,
count = count + 1;
P(count) = input(alltogether);
  댓글 수: 2
Jessica Parry
Jessica Parry 2013년 4월 7일
I cant seem to get this to work!
Walter Roberson
Walter Roberson 2013년 4월 7일
count = 0;
for orders = [0:1:y]
disp(' ')
str3 = 'The coefficient of x^';
str4 = ' is ';
alltogether = [str3 num2str(orders) str4];
count = count + 1;
P(count) = input(alltogether);
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by