Printing cell arrays issue
    3 views (last 30 days)
  
       Show older comments
    
So, I have two cell arrays. For illustration purpose, let's call them A and B. Cell A and B are both 1x6 cells, let's say that the first elements of A are 1 and 2 and the first element of B is 7. I want to print them so that the value of B stays in the middle of the elements of A, i.e, -> 1 [7] 2. Problem is, when I try to print it, it prints all of the values inside of the cell A and only then the value of B, like 1 [2] 7.
Any ideas?
3 Comments
Accepted Answer
  Stephen23
      
      
 on 16 Dec 2016
        
      Edited: Stephen23
      
      
 on 16 Dec 2016
  
      Do not use path as a variable name. As you have already been told, this is the name of a very important inbuilt function path. Use which to check if a name is already in use.
Try this code:
A = {[1,2],[1,3],[1,3,4],[1,3,6,5],[1,3,6]};
B = {  7,    9,   [9,11], [9,2,9],  [9,2]};
C = {7,9,20,20,11};
for k = 1:numel(C)
    tmp = [[NaN,B{k}];A{k}];
    fprintf('%d ',tmp(2));
    fprintf('(%d) %d ',tmp(3:end))
    fprintf('| Total = %d\n', C{k})
end
Which prints this:
1 (7) 2 | Total = 7
1 (9) 3 | Total = 9
1 (9) 3 (11) 4 | Total = 20
1 (9) 3 (2) 6 (9) 5 | Total = 20
1 (9) 3 (2) 6 | Total = 11
2 Comments
More Answers (0)
See Also
Categories
				Find more on Matrix Indexing in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

