How to solve error with accessing a multidimensional cell array?
2 次查看(过去 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!