How to solve error with accessing a multidimensional cell array?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Stephen23
el 14 de Ag. de 2017
Do not use numbered variables:
Use much simpler indexing as Jan Simon shows.
Respuestas (1)
Jan
el 12 de Ag. de 2017
Editada: Jan
el 12 de Ag. de 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 comentarios
Jan
el 14 de Ag. de 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?
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!