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!