Oliver Amundsen
Oliver Amundsen

Reputation: 1511

Produce table with text and number with fprintf in Matlab

I need to produce a table whose first 2 columns have text, and the remaining 2 have numbers. Something like this:

| Ford | Mustang | 1975 | 35 |
| Chev | Camaro  | 1976 | 38 |

I have the string in a cell, and the numeric variables in a matrix. I've tried with fprintf but can't make it work. I have no problems doing it in xlswrite, but I don't want to go that way. Any ideas please?

Thanks!

Upvotes: 0

Views: 564

Answers (1)

Micah Smith
Micah Smith

Reputation: 4453

You could use fprintf in a loop like this:

fprintf(1, '| %8s | %8s | %4d | %2d |\n', ...
    company{i}, model{i}, year(i), otherNumber(i));

to write to stdout. You can also modify the %#s if you want different spacing in your table, or provide a different file descriptor to the first argument.

Upvotes: 2

Related Questions