Have an array of 16 values, want to output them in order value by value, with the same string of text before each value

조회 수: 2 (최근 30일)
say amount = [a, b, c, d, e, f,] where a,b,c etc are numbers in an array.
Want to then output a list like this as an output with the same text string beforehand repeating but with the different values in this instance as there are 6 values to output:
For example i want the output to be:
The amount is: a
The amount is: b
The amount is: c
etc....
Want it to keep outputting until all values of amount are displayed like this

채택된 답변

Stephen23
Stephen23 2020년 11월 11일
The simple and efficient MATLAB approach is to use fprintf:
amount = [0,2,3,5,13,7];
fprintf('The amount is %d\n',amount);
The amount is 0 The amount is 2 The amount is 3 The amount is 5 The amount is 13 The amount is 7

추가 답변 (1개)

Sudhakar Shinde
Sudhakar Shinde 2020년 11월 11일
Use for loop:
amount = [a, b, c, d, e, f];
for i=1:length(amount)
disp(['The amount is: ',amount(i)]);
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by