2

I am searching for a way display cell array contents other than with celldisp that gives me an output like the example below:

celldisp(stuff)

and a typical output:

stuff{1} =
    10    70    20    50    50    90    90    30    30    60
stuff{2} =
    80    50    50    50    30    90    40    60    50    60    20    20
stuff{3} =
    20    90    10    80    20    30    30    70

I would prefer to print it out like this instead:

10    70    20    50    50    90    90    30    30    60
80    50    50    50    30    90    40    60    50    60    20    20
20    90    10    80    20    30    30    70

Is this possible? Help is much appreciated!

1 Answer 1

2

One approach could be to use num2str, which automatically pads entries with a space if no format specifier is provided. You can take advantage of this behavior with a looped fprintf call.

For example:

stuff{1} = [10, 70, 20, 50, 50, 90, 90, 30, 30, 60];
stuff{2} = [80, 50, 50, 50, 30, 90, 40, 60, 50, 60, 20, 20];
stuff{3} = [20, 90, 10, 80, 20, 30, 30, 70];

for ii = 1:numel(stuff)
    fprintf('%s\n', num2str(stuff{ii}));
end

Which produces:

>> iheartSO
10  70  20  50  50  90  90  30  30  60
80  50  50  50  30  90  40  60  50  60  20  20
20  90  10  80  20  30  30  70

You can also utilize the equivalent cellfun call if you want to be all compact and stuff:

cellfun(@(x)fprintf('%s\n', num2str(x)), stuff);
Sign up to request clarification or add additional context in comments.

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.