Printing to screen command window.

2 views (last 30 days)
Scragmore
Scragmore on 30 Nov 2011
Hi,
I am building a pseudo DB using a cell array. Each column will contain numerical array of varying sizes all calculated from the corresponding cells in previous column. So as you move across the cell array you can descend through the calculations.
The exception to this is the first row of the cell array, ca{1,:}. Each of these cells in turn contains a cell array containing the headings for the columns in the numerical arrays.
ca{1,2} = 'A' 'B' 'C'....
ca{2,2} = (dataA, dataB, datac) where data is numerical
I am trying to write a little function for the command window that will take this txt and return it, a bit like help file but for data definition. What I am after to return;
>>askDB(ca)
ans =
layer 1
a
b
c...
layer 2
A
B
C...
So far I have this code, it takes the top row of cells and changes the contain cells from row to column format. But I am tying my self in knots trying to work out how to achieve my output with the various ways to print or send output.
function arCout = arCont(arCin)
% List the contents of cell array.
% Will take the first row and extract the headings from the cells.
% % INPUT
% Cell Array{n,n}(,);
% CN{1,n} char array, data headings and description
[xL, yL] = size(arCin);
arnew = arCin(1,1:yL);
for ii = 1:yL
[xLx, yLy] = size(arnew{1,ii});
arnew{1,ii} = arnew{1,ii}(1,:);
arnew{1,ii} = reshape(arnew{1,ii}(), yLy, []);
end
arCout = arnew;
Can you help in returning my cell contents is a logical concise format.
Regards,
AD
  1 Comment
Scragmore
Scragmore on 1 Dec 2011
I have managed to construct something that will print what I want;
fprintf('layer 1\n')
fprintf('\t%s\n', TPin{ia,ib}{:})
However my problem now is that some of my heading cell arrays only contain one entry and when the above code passes these I get the error;
??? Cell contents reference from a non-cell array object.
Error in ==> Tprint at 4
fprintf('\t%s\n', TPin{ia,ib}{:})
and the code needs to change in order for these cells to pass. To;
fprintf('\t%s\n', TPin{ia,ia})
Is there a way around this or do I have to put an 'if' loop in as a contingency.

Sign in to comment.

Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!