Giving names to cells

10 visualizaciones (últimos 30 días)
Ellen
Ellen el 28 de Mayo de 2020
Comentada: Ameer Hamza el 31 de Mayo de 2020
Hi!
I am working with multiple arrays which some are split up and other are not. They are stored in a cell type called output.mat. Now I would like to name each cell (also the cells which are located inside cells) based on the names of existing files. I made the following for this:
files = dir('*.roi');
for i=1:length(output)
data = importdata(files(i).name);
chr = files(i).name;
if ~exist(output{i}{i})
save({chr,'.txt'},'output{i}')
else
for ii=1:length(output{i}{i});
save([chr,'_',ii,'.txt'],'output{i}{i}');
end
end
end
However it is not working due to the exist function. The problem is that some cells have cells inside them and others don't. If the cell has a cell inside, I'd like to name them 'filename.1' (and 'filename.2' for the second cell inside the cell and so on). If there is just one cell without an extra cell in it, I'd like to name it 'filename'. So first I'd like to determine if a cell has a cell inside it. I used the exist function for this but obviously it doesn't work. Or do I need to extract all the cells first?
Can someone help me with this?
I apologize if the story is a bit vague.

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 29 de Mayo de 2020
Use iscell() function
if ~iscell(output{i})
Also, note that save() will not accept indexing like this 'output{i}'. You will need to create a temporary variable.
Instead of
save({chr,'.txt'},'output{i}')
write
temp = output{i}
save({chr,'.txt'},'temp') % use appropriate name in place of temp
  2 comentarios
Ellen
Ellen el 31 de Mayo de 2020
Thanks, this helped a lot!
Ameer Hamza
Ameer Hamza el 31 de Mayo de 2020
I am glad to be of help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by