How to solve error with accessing a multidimensional cell array?

2 visualizaciones (últimos 30 días)
Glazio
Glazio el 12 de Ag. de 2017
Editada: Glazio el 16 de Ag. de 2017
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)?

Respuestas (1)

Jan
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
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?
Glazio
Glazio el 14 de Ag. de 2017
@Jan Simon:
Yes, I have read the documentation.
It accepts a cell matrix for YY, therefore I've crated YY with the follwoing dimensions:
  • YY (31x10)
  • YY{i,j} (1000x3)
Each column in YY{i,j} represents a different performance-measure (1st column: NSE, 2nd column: RMSE, 3rd column: BIAS).
When I run the function like this:
[ YF, Fu, Fc ] = pawn_cdfs(Yu,YY) ;
it works (without an error message), but I can't carry out the further evaluations here for a special performance-measure.
So I just want that only the first column or second column or third column is taken into account and not just the first or all under once.
My attempts to implement this failed (see error messages in the comments/questions above).
Which solution approach would you suggest?

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by