Continually prompt for the input of 3x1 column vectors

9 views (last 30 days)
Hello,
I am trying to find a way for my code to continually prompt for the input of 3x1 column vectors, and then create a 3xn matrix where n is the number of vectors the user inputs and each column of the matrix is one of the vectors. I also need to be able to label each vector, although the labels should not be present alongside the matrix. As an example, if the user needed to input three vectors, it would function something like this:
label1 = [1;2;3]
label2=[4;5;6]
label3=[7;8;9]
The resulting matrix would be
group=[1 4 7; 2 5 8; 3 6 9]
I am a bit of a novice with matlab and I am not sure where to begin with this code, aside from possibly using a question dialog box after each user input to determine if more input will occur. The main struggle is the continuous input.
Any help would be greatly appreciated
Thank you
  1 Comment
Stephen23
Stephen23 on 22 Dec 2018
Edited: Stephen23 on 22 Dec 2018
"I am a bit of a novice with matlab and I am not sure where to begin with this code"
Start by reading this:
Probably the easiest ways to let your user enter data is either with a GUI, e.g. uitable (intuitive but slow), or by simply writing functions and letting the user decide how they want to define their own data (faster and much more efficient).

Sign in to comment.

Accepted Answer

Samuel Jones
Samuel Jones on 27 Dec 2018
For anyone who has a similar question to mine, what I found to work best was to create a an empty 1x3 matrix folllowed by a while loop which prompted for the input of the individual input of the 3 numbers within each new matrix. Then, using this page: https://www.mathworks.com/help/matlab/math/creating-and-concatenating-matrices.html I expanded the original empty matrix with the new values. I used a loop counting method I found on this page: https://www.mathworks.com/matlabcentral/answers/123124-counting-how-many-times-a-loop-loops to continually build the matrix by expanding it relative to the number of times the loop was performed. In my case I set the "loopcount" equal to 1 prior to the while loop so that the value associated with "loopcount" could be used to designate the column of the matrix during expantion. I then ended the loop with a questdlg.

More Answers (1)

madhan ravi
madhan ravi on 21 Dec 2018
result=[label1(:) label2(:) label3(:)]
  2 Comments
Samuel Jones
Samuel Jones on 21 Dec 2018
Could this solution be used to work with some form of a loop and an input dialog box? Your solution works when the number of vectors is fixed at three. The goal is to be able to perform the task with any number of vectors with the same dimensions. I used three vectors as an example but I need to be able to use the same code regardless of the resulting matrix size.
madhan ravi
madhan ravi on 22 Dec 2018
Yes make a loop and save each vectors as a column and then concatenate them.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!