How to solve error with accessing a multidimensional cell array?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Stephen23
le 14 Août 2017
Do not use numbered variables:
Use much simpler indexing as Jan Simon shows.
Réponses (1)
Jan
le 12 Août 2017
Modifié(e) : Jan
le 12 Août 2017
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 commentaires
Jan
le 14 Août 2017
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?
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!