1

I want to store user inputs in an array, but when a person enters a new number, the previous input gets replaced. How can I create such an array in Matlab such that I can store all inputs without replacement? I am a beginner so bear with me

Thanks

2 Answers 2

1

You simply need to copy the contents of the input buffer into a data struct that won't be overwritten.

Cell arrays are good for that (see the userInputs variable below) . Without better knowledge of your code, I'm guessing the user input is stored in a variable named buffer. Here's how I would do it:

% a new buffer comes in
userInputs{iInput} = buffer;
iInput = iInput + 1;
% keep looking for more inputs

Good luck!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. How can we flip a graph about x-axis.
0

If you want a numeric matrix here is an example:

n = 2; %# number of rows
m = 3; %# number of columns
out = zeros(n,m); %# the output
k = 1; %# counter
while k <= n*m
    x = input('Enter a number or Enter to stop: ');
    if isempty(x)
        break
    else
        out(k)=x;
    end
    k=k+1;
end
disp(xx)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.