Printing cell arrays issue
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Stephen23
2016-12-16
编辑:Stephen23
2016-12-16
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!