How to enter user values into an existing matrix.

4 ビュー (過去 30 日間)
Manuel
Manuel 2022 年 12 月 9 日
回答済み: Eric Delgado 2022 年 12 月 9 日
Hi everyone,
I am currently working on a project that takes values from a user on a running script and input that into a matrix that has been created in the script. Lets say i have a 5x5 matrix and the user is presented with and asked to memorize 5 random numbers per for loop, I need my code to take the 5 values that the user inputs into the command window and place them wach column of the matrix.
Thanks!

回答 (1 件)

Eric Delgado
Eric Delgado 2022 年 12 月 9 日
Try this...
originalMatrix = randi(10,5);
inputArray = zeros(5,1);
for ii = 1:numel(inputArray)
inputArray(ii) = input(sprintf('inputArray(%d): ', ii));
end
originalMatrix(:,end+1) = inputArray

カテゴリ

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