How to solve error with accessing a multidimensional cell array?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a cell array YY (with 31 X 10 cells) and in each cell are 1000 rows and 3 columns. The corresponding Matrix Yu has 1000 lines and 3 columns.
The execution of the following function works as follows:
[ YF, Fu, Fc ] = pawn_cdfs(Yu,YY) ;
No error message is displayed here, but only the first column of the individual cells is processed.
If I want to access the individual columns (1st column, 2nd column, ...) like this:
j = 1;
[YF1, Fu1, Fc1] = pawn_cdfs(Yu(:,j),YY(:,j));
j = 2;
[YF2, Fu2, Fc2] = pawn_cdfs(Yu(:,j),YY(:,j));
j = 3;
[YF3, Fu3, Fc3] = pawn_cdfs(Yu(:,j),YY(:,j));
this error message appears:
Error using pawn_cdfs (line 60)
'Y' and 'YY{1}'must have the same number of colums
Error in workflow_pawn_ses (line 84)
[YF1, Fu1, Fc1] = pawn_cdfs(Yu(:,j),YY(:,j));
Ie. The corresponding column of YY is accessed here and not on that of the respective cell.
Also the attempt with a loop did not work:
for k=1:31
for k = 1:10
j = 1;
[YF1, Fu1, Fc1] = pawn_cdfs(Yu(:,j),YY{k,l}(:,j));
....
end
end
Does anyone have an idea how to solve this problem (access and work with respective column)?
댓글 수: 1
답변 (1개)
Jan
2017년 8월 12일
편집: Jan
2017년 8월 12일
You need the complete Yu matrix for each element of the cell array YY:
[YF1, Fu1, Fc1] = pawn_cdfs(Yu, YY(:,j));
Avoid the creation of variables with an index hidden in the name. This is not flexible and causes troubles frequently.
If pawn_cdfs does not process the complete cell array, it contains most likely a lengtt(YY), when numel(YY) is meant. If you post the code, an improvement can be suggested.
But you can get a workaround also by providing the complete cell matrix as a single vector:
[YF, Fu, Fc] = pawn_cdfs(Yu, YY(:)) ;
% inserted: ^^^
Then you can reshape the output afterwards, perhaps as:
YF = reshape(YF, size(YY));
Fu = reshape(Fu, size(YY));
Fc = reshape(Fc, size(YY));
But this is a guess only, because it is not clear, what this function replies.
댓글 수: 3
Jan
2017년 8월 14일
I cannot follow you. What is "the first columns (within each cell)"?
Did you read the documentation of the function? It accepts a cell matrix for YY. Perhaps your observation "only the first column of the individual cells is processed" is not correct?
% Y = output sample for estimating the unconditional CDF - matrix (N,P)
% YY = output samples for the conditional CDFs - cell array (M,n)
It does not look like (Yu(:,j),YY(:,j)) are useful inputs. And "accessing individual columns" might not be meaningful also.
So please restart to explain: What do you want to solve actually?
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!