Help placing user input into an element in a row vector

5 ビュー (過去 30 日間)
Marcus Evans
Marcus Evans 2021 年 3 月 28 日
編集済み: per isakson 2021 年 3 月 29 日
This is what I have so far, having trouble adding user input into a row vector the same amount of times as for loop
score =inputdlg('Please enter a number of scores between 1 and 10:\n'); % Prompt and Get a score input
data = str2double(score);
x = [];
if 1<= data && 10>=data
for i = 1 < score
x(end+1) = input('Input a number: ');
end
else
errordlg('Wrong Input')
end

回答 (2 件)

VBBV
VBBV 2021 年 3 月 28 日
編集済み: VBBV 2021 年 3 月 29 日
%if true
for i = 1 : data
x(i) = input('Input a number: ');
end
Change the for loop structure as above
  1 件のコメント
VBBV
VBBV 2021 年 3 月 29 日
Try using the data. variable
it works
for i = 1 : data
x(i) = input('Input a number: ');
end

サインインしてコメントする。


per isakson
per isakson 2021 年 3 月 28 日
Look up for in the documentation ... replace
for i = 1 < score
by
for i = 1 : data
  2 件のコメント
Marcus Evans
Marcus Evans 2021 年 3 月 29 日
When I tired to run it making the correct changes this is what I got
Operator ':' is not supported for operands of type 'cell'.
Any clue as to why?
per isakson
per isakson 2021 年 3 月 29 日
編集済み: per isakson 2021 年 3 月 29 日
The operator ':' appears in the for-statement and the value of the variable, data, should be double. That error should not occur. Did you really use the for-statement
for i = 1 : data
If you did, run
whos data
and show me the output

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by