Displaying cells which have different sizes
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi everyone. Lets say I have a cell. I tried different ways but I could'nt make it properly.
Y{1,1}=['WATER'] Y{2,1}=2
Y{2,1}=['WATER' 'COKE'] Y{2,2}=3
my code to display these are ;
a=0;
while (a<length(Y))
a=a+1;
disp(['#' num2str(a) ':' (Y{a,1}) ' GET-->' mat2str(Y{a,2})])
end
RESULT
'#' '1' ':' 'WATER' 'GET-->' '2'
'#' '2' ':' 'WATER' 'COKE' 'GET-->' '3'
How can I get something like that
#1 : 'WATER' GET--> 2
#1 : 'WATER' 'COKE' GET--> 3
댓글 수: 0
답변 (2개)
madhan ravi
2020년 7월 9일
for k= 1:size(Y,1)
fprintf('#1 : %s GET--> %d\n', Y{k,1}, Y{k,2})
end
댓글 수: 3
madhan ravi
2020년 7월 9일
clear all
Y{1,1}=['WATER']
Y{1,2}=2
Y{2,1}=['WATER', 'COKE']
Y{2,2}=3
for k= 1:size(Y,1)
s = repmat('%s', 1, numel(Y{k,1}));
fprintf('#1 :',s,' GET--> %d\n', Y{k,1}, Y{k,2})
end
Image Analyst
2020년 7월 9일
Try this:
Y = {1, 'WATER', []; ...
1, 'WATER', 'COKE'}
You get:
Y =
2×3 cell array
{[1]} {'WATER'} {0×0 double}
{[1]} {'WATER'} {'COKE' }
The 1,3 cell is still there since you can't have missing elements in an array. Like any array, cell arrays included, you can't have 2 columns in the first row and 3 columns in the second row.
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!