Calculate number in a matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yu-Wei Tu
am 20 Mai 2021
Kommentiert: Yu-Wei Tu
am 20 Mai 2021
Hi, how can I calculate a matrix by asking a user's input? For example, ask user to input a matrix such as [1 5 3] and change the middle number by adding the numbers next to it and take average, So in this case it would be [1 (1+5+3)/3 3] which will output [1 3 3]. Thank you.
2 Kommentare
Jan
am 20 Mai 2021
This sounds like a homework question. Then please post, what you have tried so far and ask a specific question.
Akzeptierte Antwort
Atsushi Ueno
am 20 Mai 2021
Bearbeitet: Atsushi Ueno
am 20 Mai 2021
> how can I calculate a matrix by asking a user's input?
prompt = 'input a matrix such as [1 5 3]? ';
try
x = input(prompt);
if all(size(x) == [1 3])
x(2) = sum(x) / 3.0;
disp(['calculated result is [' num2str(x) ']']);
else
disp('size of input matrix is not 1 row by 3 columns.');
end
catch
disp('input style is not as a matrix!');
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!