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
댓글 수: 2
추가 답변 (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!