Filter löschen
Filter löschen

Looping through a cell with datasets

2 Ansichten (letzte 30 Tage)
Eric
Eric am 2 Dez. 2014
Kommentiert: Eric am 2 Dez. 2014
Hi everybody,
I have a question about looping through a cell with multiple dataset (1x9 cell with each cell being 19x19 double). I try to use the following script:
DataFiles = {dataset1, dataset2, dataset3};
for iity = 1:length(DataFiles) [row, col] = ind2sub(size(DataFiles(1,iity)), find(DataFiles(1,iity)>0.5)); sig_results = row; sig_results(:,2) = col;
plot.cs = sig_results;
end
and I keep getting the following error:
Undefined function 'gt' for input arguments of type 'cell'.
Does anyone know what that means? And what seems to be the problem?
Best regards,
Christian

Akzeptierte Antwort

Stephen23
Stephen23 am 2 Dez. 2014
Bearbeitet: Stephen23 am 2 Dez. 2014
This error message is telling you that the function gt (which you use the alias of with ...>0.5 ) is not defined for cell array input values. The function gt requires numeric array inputs, which you have inside your cell array... the trick is to use the correct indexing to get the numeric arrays back out. The difference is in the braces/brackets:
DataFiles = {dataset1, dataset2, dataset3};
for iity = 1:length(DataFiles)
[row, col] = ind2sub(size(DataFiles{iity}), find(DataFiles{iity}>0.5));
sig_results(:,1) = row;
sig_results(:,2) = col;
plot.cs = sig_results;
end
In essence:
  • Brackets () always refer to the elements of the array that they are indexing, so MATLAB returns an array of the same type as the array that you are indexing into.
  • Braces {} can be used with cell arrays to return whatever is inside those cells of a cell array (referred to as "content indexing" in the documentation):
  1 Kommentar
Eric
Eric am 2 Dez. 2014
Thank you very much Stephen.
Best regards,
Christian

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by