fprintf two 3x1 matrix's w/ text

조회 수: 1 (최근 30일)
Brennan
Brennan 2022년 10월 18일
편집: Karim 2022년 10월 18일
using fprint f, lets say you have two matrix...
bearing=(30:50:60)
range=(600,1237,579) <---- these would be 3x1
like bearing looks like this = 30
50
60
not sure if i wrote those vectors or matrix or whatever they are in the beggining correct but it looks like the example.
so its in a colum you know...
so say you have that and you wanna display using fprintf:
The potential PIW bears 30 from the CG Asset at a range of 600 yards.
The potential PIW bears 50 from the CG Asset at a range of 1237 yards.
The potential PIW bears 60 from the CG Asset at a range of 579 yards.
I tried
fprintf('The potential PIW bears %g from the CG Asset at a range of %g yards.', [bearing, range])
and
fprintf('The potential PIW bears %d from the CG Asset at a range of %g yards.', [bearing, range])
could someone help?

채택된 답변

Karim
Karim 2022년 10월 18일
편집: Karim 2022년 10월 18일
Make sure that you add an end of line character "\n" to the end of the fprintf statement, otherwise evrtything will be printed on a single line. Hope it helps.
bearing = [30 50 60];
range = [600 1237 579];
fprintf('The potential PIW bears %i from the CG Asset at a range of %i yards.\n', [bearing;range])
The potential PIW bears 30 from the CG Asset at a range of 600 yards. The potential PIW bears 50 from the CG Asset at a range of 1237 yards. The potential PIW bears 60 from the CG Asset at a range of 579 yards.

추가 답변 (1개)

David Hill
David Hill 2022년 10월 18일
bearing=[30 50 60];range=[600 1237 579];
for k=1:3
fprintf('The potential PIW bears %g from the CG Asset at a range of %g yards.\n',bearing(k),range(k));
end
The potential PIW bears 30 from the CG Asset at a range of 600 yards. The potential PIW bears 50 from the CG Asset at a range of 1237 yards. The potential PIW bears 60 from the CG Asset at a range of 579 yards.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by