MATLAB Answers

How can I use input values to create an array?

458 views (last 30 days)
Nureen Hoosein
Nureen Hoosein on 31 Mar 2015
Answered: Shagun Sharma on 21 Jan 2020
How would I get the xii input values to form an array called xi in the following code?
for ii = 1:5 xii = input('Enter value or enter 100 to stop: '); if xii == 100 break; end end
xi=[xii];

  0 Comments

Sign in to comment.

Answers (3)

Ganesh Gaonkar
Ganesh Gaonkar on 31 Mar 2015
You should be able to use 'input' function as shown here: http://in.mathworks.com/help/matlab/ref/input.html

  0 Comments

Sign in to comment.


Konstantinos Sofos
Konstantinos Sofos on 31 Mar 2015
xi = []; % Initialize array/vector
for i=1:5
xii = input('Enter value or enter 100 to stop: ');
if xii==100
break
else
xi(end+1)=xii;
end
end

  0 Comments

Sign in to comment.


Shagun Sharma
Shagun Sharma on 21 Jan 2020
%For making an array from input values follow the below sequence (customise as per your requirenments):
%Firstly initialize an array
xi = [];
for i=1:5
xii = input('Enter value or enter 100 to stop: ');
if (xii==100)
break;
else
xi(i)=xii;
end
end

  0 Comments

Sign in to comment.

Sign in to answer this question.