0

I am using matlab sprintf to print numbers stored in 1D array with specific format. For example, I have two array A=[1 2 3], B=[4 5 6], I expect it to print as

1/4; 2/5; 3/6

I try the following command

p=[1 2 3];
q=[4 5 6];
sprintf('%d/%d; ', p, q)

But it gave me

1/2; 3/4; 5/6

Any way to work it around? Thanks

3 Answers 3

1
p=[1 2 3];
q=[4 5 6];
sprintf('%d/%d; ', [p; q])
Sign up to request clarification or add additional context in comments.

Comments

1

You can also change display format rat:

format rat
A = [1 2 3];
B = [4 5 6];

And in the command window

A./B
ans =
       1/4            2/5            1/2

Comments

0

for i=1:n sprintf('%d/%d;', p[i], q[i])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.