How to create an array with user inputs?

Hello, I am trying to create an array with user inputs. For example, if the user types 3, 5, 7, the array comes out to be [3,5,7]. How can I do this? Thanks in advance for your help!

回答 (2 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 8 月 5 日

0 投票

You can consider using input() prompt. See this doc with examples: https://www.mathworks.com/help/matlab/ref/input.html?s_tid=srchtitle

1 件のコメント

Soeun Lee
Soeun Lee 2021 年 8 月 5 日
Thanks for your answer. I am using the input() prompt, but the only problem is I don't know how to put the user inputs into an array. Any ideas?

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

d bhaskar
d bhaskar 2023 年 2 月 24 日

0 投票

clc
clear all
n=2; m=2;
for i=1:n
for j=1:m
fprintf('Enter a(%d,%d)=',i,j);
a(i,j)=input('');
end
end

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2021 年 8 月 5 日

回答済み:

2023 年 2 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by