Script that asks for matrix as input

I am trying to write a script that I will use on a number of matrices so I was trying to have the script ask for input as to which matrix it should be run on. It worked for a single run and then stopped working. This is how I wrote it into the script:
Processing = input('The matrix to be analyzed is:');
This seems like it should be simple, but I just can't seem to find the answer. Thank you in advance.

1 件のコメント

Ibrahim Sherif
Ibrahim Sherif 2021 年 5 月 2 日
Use this script program bro:
x=input('Enter the number of rows : ');
y=input('Enter the number of columns : ');
for r=1:x
for c=1:y
fprintf('Enter the value in row %d column %d\n',r,c);
M(r,c)=input('');
end
end
display(M)

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

 採用された回答

Youssef  Khmou
Youssef Khmou 2014 年 3 月 31 日

0 投票

For a single input , what you described is sufficient :
>>A=input(' Matrix :\n');
>> % Enter the matrix , example [4 5 6;3 6 9];
For a number of inputs you only need a manifold where to store them, the rigorous way is to use cells :
>>N=10;
>>B=cell(N,1);
>>for n=1:N
fprintf(' Entre matrix %d\n',n);
B{n}=input('');
end

3 件のコメント

Ryan
Ryan 2014 年 3 月 31 日
Thank you.
Ryan
Ryan 2014 年 3 月 31 日
That didn't work. It is saying that the index exceeds matrix dimensions on that line, which makes no sense to me.
Youssef  Khmou
Youssef Khmou 2014 年 3 月 31 日
That example is working, can you post the script?
i think that problem is due to variables, are your variables names distinctes?

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

その他の回答 (1 件)

Abhishek Pawarq
Abhishek Pawarq 2021 年 8 月 22 日

0 投票

a = input('Enter the number of rows');
b = input('Enter the number of coloumns');
for i=1:a
for j=1:b
p(i,j)=input('Enter the elements');
end
end
p=reshape(p,a,b)

カテゴリ

ヘルプ センター および File ExchangePerformance and Memory についてさらに検索

タグ

質問済み:

2014 年 3 月 31 日

回答済み:

2021 年 8 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by